computer: part 5

This commit is contained in:
nym21
2025-04-06 12:01:45 +02:00
parent 810cdbd790
commit 1639df5616
21 changed files with 602 additions and 179 deletions

View File

@@ -1,12 +1,12 @@
use std::{fs, path::Path};
use brk_core::{CheckedSub, Dateindex, Timestamp};
use brk_core::{CheckedSub, CounterU32, Timestamp};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{
ComputedVec, Indexes,
Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
indexes,
};
@@ -14,8 +14,7 @@ use super::{
#[derive(Clone)]
pub struct Vecs {
pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>,
pub dateindex_to_block_count: ComputedVec<Dateindex, u16>,
pub dateindex_to_total_block_count: ComputedVec<Dateindex, u32>,
pub indexes_to_block_count: ComputedVecsFromHeight<CounterU32>,
}
impl Vecs {
@@ -33,15 +32,12 @@ impl Vecs {
.add_minmax()
.add_average(),
)?,
dateindex_to_block_count: ComputedVec::forced_import(
&path.join("dateindex_to_block_count"),
Version::ONE,
compressed,
)?,
dateindex_to_total_block_count: ComputedVec::forced_import(
&path.join("dateindex_to_total_block_count"),
indexes_to_block_count: ComputedVecsFromHeight::forced_import(
path,
"block_count",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?,
})
}
@@ -53,10 +49,14 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
let indexer_vecs = indexer.mut_vecs();
self.indexes_to_block_interval.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
let indexer_vecs = indexer.mut_vecs();
v.compute_transform(
starting_indexes.height,
indexer_vecs.height_to_timestamp.mut_vec(),
@@ -72,9 +72,23 @@ impl Vecs {
exit,
)
},
)?;
self.indexes_to_block_count.compute(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
let indexer_vecs = indexer.mut_vecs();
v.compute_transform(
starting_indexes.height,
indexer_vecs.height_to_weight.mut_vec(),
|(h, ..)| (h, CounterU32::from(1_u32)),
exit,
)
},
)?;
Ok(())
@@ -82,11 +96,8 @@ impl Vecs {
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![
self.dateindex_to_block_count.any_vec(),
self.dateindex_to_total_block_count.any_vec(),
],
self.indexes_to_block_interval.any_vecs(),
self.indexes_to_block_count.any_vecs(),
]
.concat()
}

View File

@@ -1,7 +1,7 @@
use std::path::Path;
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed, Result, StoredIndex, StoredType, Version};
use brk_vec::{AnyStorableVec, Compressed, Result, StorableVec, StoredIndex, StoredType, Version};
use crate::storage::vecs::base::ComputedVec;
@@ -24,6 +24,7 @@ where
pub _10p: Option<ComputedVec<I, T>>,
pub min: Option<ComputedVec<I, T>>,
pub last: Option<ComputedVec<I, T>>,
pub total: Option<ComputedVec<I, T>>,
}
impl<I, T> ComputedVecBuilder<I, T>
@@ -37,71 +38,119 @@ where
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
// let name = path.file_name().unwrap().to_str().unwrap().to_string();
let key = I::to_string().split("::").last().unwrap().to_lowercase();
let only_one_active = options.is_only_one_active();
let prefix = |s: &str| {
let default = || path.join(format!("{key}_to_{name}"));
let prefix = |s: &str| path.join(format!("{key}_to_{s}_{name}"));
let maybe_prefix = |s: &str| {
if only_one_active {
path.with_file_name(format!("{key}_to_{name}"))
default()
} else {
path.with_file_name(format!("{key}_to_{s}_{name}"))
prefix(s)
}
};
let suffix = |s: &str| {
let suffix = |s: &str| path.join(format!("{key}_to_{name}_{s}"));
let maybe_suffix = |s: &str| {
if only_one_active {
path.with_file_name(format!("{key}_to_{name}"))
default()
} else {
path.with_file_name(format!("{key}_to_{name}_{s}"))
suffix(s)
}
};
let s = Self {
first: options.first.then(|| {
ComputedVec::forced_import(&prefix("first"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_prefix("first"), Version::ONE, compressed)
.unwrap()
}),
last: options.last.then(|| {
ComputedVec::forced_import(
&path.with_file_name(format!("{key}_to_{name}")),
&path.join(format!("{key}_to_{name}")),
Version::ONE,
compressed,
)
.unwrap()
}),
min: options.min.then(|| {
ComputedVec::forced_import(&suffix("min"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("min"), Version::ONE, compressed).unwrap()
}),
max: options.max.then(|| {
ComputedVec::forced_import(&suffix("max"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("max"), Version::ONE, compressed).unwrap()
}),
median: options.median.then(|| {
ComputedVec::forced_import(&suffix("median"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("median"), Version::ONE, compressed)
.unwrap()
}),
average: options.average.then(|| {
ComputedVec::forced_import(&suffix("average"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("average"), Version::ONE, compressed)
.unwrap()
}),
sum: options.sum.then(|| {
ComputedVec::forced_import(&suffix("sum"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("sum"), Version::ONE, compressed).unwrap()
}),
total: options.total.then(|| {
ComputedVec::forced_import(&prefix("total"), Version::ONE, compressed).unwrap()
}),
_90p: options._90p.then(|| {
ComputedVec::forced_import(&suffix("90p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("90p"), Version::ONE, compressed).unwrap()
}),
_75p: options._75p.then(|| {
ComputedVec::forced_import(&suffix("75p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("75p"), Version::ONE, compressed).unwrap()
}),
_25p: options._25p.then(|| {
ComputedVec::forced_import(&suffix("25p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("25p"), Version::ONE, compressed).unwrap()
}),
_10p: options._10p.then(|| {
ComputedVec::forced_import(&suffix("10p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&maybe_suffix("10p"), Version::ONE, compressed).unwrap()
}),
};
Ok(s)
}
pub fn extend(
&mut self,
max_from: I,
source: &mut StorableVec<I, T>,
exit: &Exit,
) -> Result<()> {
if self.total.is_none() {
return Ok(());
};
let index = self.starting_index(max_from);
let total_vec = self.total.as_mut().unwrap();
source.iter_from(index, |(i, v)| {
let prev = i
.to_usize()
.unwrap()
.checked_sub(1)
.map_or(T::from(0_usize), |prev_i| {
total_vec
.get(I::from(prev_i))
.unwrap()
.unwrap_or(&T::from(0_usize))
.to_owned()
});
let value = v.clone() + prev;
total_vec.forced_push_at(i, value, exit)?;
Ok(())
})?;
self.safe_flush(exit)?;
Ok(())
}
pub fn compute<I2>(
&mut self,
max_from: I,
@@ -134,7 +183,8 @@ where
let first_index = first_index.to_usize()?;
let last_index = last_index.to_usize()?;
let needs_sum_or_average = self.sum.is_some() || self.average.is_some();
let needs_sum_or_total = self.sum.is_some() || self.total.is_some();
let needs_average_sum_or_total = needs_sum_or_total || self.average.is_some();
let needs_sorted = self.max.is_some()
|| self._90p.is_some()
|| self._75p.is_some()
@@ -142,7 +192,7 @@ where
|| self._25p.is_some()
|| self._10p.is_some()
|| self.min.is_some();
let needs_values = needs_sorted || needs_sum_or_average;
let needs_values = needs_sorted || needs_average_sum_or_total;
if needs_values {
let mut values =
@@ -180,7 +230,7 @@ where
}
}
if needs_sum_or_average {
if needs_average_sum_or_total {
let len = values.len();
if let Some(average) = self.average.as_mut() {
@@ -193,9 +243,22 @@ where
average.forced_push_at(i, avg, exit)?;
}
if let Some(sum_vec) = self.sum.as_mut() {
if needs_sum_or_total {
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
sum_vec.forced_push_at(i, sum, exit)?;
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
if let Some(total_vec) = self.total.as_mut() {
let prev = i.to_usize().unwrap().checked_sub(1).map_or(
T::from(0_usize),
|prev_i| {
total_vec.get(I::from(prev_i)).unwrap().unwrap().to_owned()
},
);
total_vec.forced_push_at(i, prev + sum, exit)?;
}
}
}
}
@@ -264,9 +327,10 @@ where
let first_index = Some(first_index.to_usize()? as i64);
let last_index = Some(last_index.to_usize()? as i64);
let needs_sum_or_average = self.sum.is_some() || self.average.is_some();
let needs_sum_or_total = self.sum.is_some() || self.total.is_some();
let needs_average_sum_or_total = needs_sum_or_total || self.average.is_some();
let needs_sorted = self.max.is_some() || self.min.is_some();
let needs_values = needs_sorted || needs_sum_or_average;
let needs_values = needs_sorted || needs_average_sum_or_total;
if needs_values {
if needs_sorted {
@@ -291,7 +355,7 @@ where
}
}
if needs_sum_or_average {
if needs_average_sum_or_total {
if let Some(average) = self.average.as_mut() {
let values = source
.average
@@ -309,14 +373,27 @@ where
average.forced_push_at(i, avg, exit)?;
}
if let Some(sum_vec) = self.sum.as_mut() {
if needs_sum_or_total {
let values = source
.sum
.as_ref()
.unwrap()
.collect_range(first_index, last_index)?;
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
sum_vec.forced_push_at(i, sum, exit)?;
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
if let Some(total_vec) = self.total.as_mut() {
let prev = i.to_usize().unwrap().checked_sub(1).map_or(
T::from(0_usize),
|prev_i| {
total_vec.get(I::from(prev_i)).unwrap().unwrap().to_owned()
},
);
total_vec.forced_push_at(i, prev + sum, exit)?;
}
}
}
}
@@ -381,6 +458,9 @@ where
if let Some(sum) = self.sum.as_ref() {
v.push(sum.any_vec());
}
if let Some(total) = self.total.as_ref() {
v.push(total.any_vec());
}
if let Some(_90p) = self._90p.as_ref() {
v.push(_90p.any_vec());
}
@@ -419,6 +499,9 @@ where
if let Some(sum) = self.sum.as_mut() {
sum.safe_flush(exit)?;
}
if let Some(total) = self.total.as_mut() {
total.safe_flush(exit)?;
}
if let Some(_90p) = self._90p.as_mut() {
_90p.safe_flush(exit)?;
}
@@ -449,6 +532,7 @@ pub struct StorableVecGeneatorOptions {
min: bool,
first: bool,
last: bool,
total: bool,
}
impl StorableVecGeneatorOptions {
@@ -507,6 +591,11 @@ impl StorableVecGeneatorOptions {
self
}
pub fn add_total(mut self) -> Self {
self.total = true;
self
}
pub fn rm_min(mut self) -> Self {
self.min = false;
self
@@ -552,6 +641,11 @@ impl StorableVecGeneatorOptions {
self
}
pub fn rm_total(mut self) -> Self {
self.total = false;
self
}
pub fn add_minmax(mut self) -> Self {
self.min = true;
self.max = true;
@@ -589,10 +683,18 @@ impl StorableVecGeneatorOptions {
self.min,
self.first,
self.last,
self.total,
]
.iter()
.filter(|b| **b)
.count()
== 1
}
pub fn copy_self_extra(&self) -> Self {
Self {
total: self.total,
..Self::default()
}
}
}

View File

@@ -2,6 +2,7 @@ use std::path::Path;
use brk_core::{Dateindex, Decadeindex, Monthindex, Quarterindex, Weekindex, Yearindex};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
@@ -14,6 +15,7 @@ where
T: ComputedType + PartialOrd,
{
pub dateindex: ComputedVec<Dateindex, T>,
pub dateindex_extra: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
@@ -33,6 +35,9 @@ where
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let dateindex_extra =
ComputedVecBuilder::forced_import(path, name, compressed, options.copy_self_extra())?;
let options = options.remove_percentiles();
Ok(Self {
@@ -41,6 +46,7 @@ where
version,
compressed,
)?,
dateindex_extra,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
monthindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
quarterindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
@@ -51,15 +57,31 @@ where
pub fn compute<F>(
&mut self,
mut compute: F,
indexer: &mut Indexer,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Dateindex, T>) -> Result<()>,
F: FnMut(
&mut ComputedVec<Dateindex, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{
compute(&mut self.dateindex)?;
compute(
&mut self.dateindex,
indexer,
indexes,
starting_indexes,
exit,
)?;
self.dateindex_extra
.extend(starting_indexes.dateindex, self.dateindex.mut_vec(), exit)?;
self.weekindex.compute(
starting_indexes.weekindex,
@@ -107,6 +129,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![self.dateindex.any_vec()],
self.dateindex_extra.any_vecs(),
self.weekindex.any_vecs(),
self.monthindex.any_vecs(),
self.quarterindex.any_vecs(),

View File

@@ -4,6 +4,7 @@ use brk_core::{
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Weekindex, Yearindex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
@@ -16,6 +17,7 @@ where
T: ComputedType + PartialOrd,
{
pub height: ComputedVec<Height, T>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
@@ -44,12 +46,16 @@ where
compressed,
)?;
let height_extra =
ComputedVecBuilder::forced_import(path, name, compressed, options.copy_self_extra())?;
let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
let options = options.remove_percentiles();
Ok(Self {
height,
height_extra,
dateindex,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
@@ -63,15 +69,25 @@ where
pub fn compute<F>(
&mut self,
mut compute: F,
indexer: &mut Indexer,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Height, T>) -> Result<()>,
F: FnMut(
&mut ComputedVec<Height, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{
compute(&mut self.height)?;
compute(&mut self.height, indexer, indexes, starting_indexes, exit)?;
self.height_extra
.extend(starting_indexes.height, self.height.mut_vec(), exit)?;
self.dateindex.compute(
starting_indexes.dateindex,
@@ -135,6 +151,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![self.height.any_vec()],
self.height_extra.any_vecs(),
self.dateindex.any_vecs(),
self.weekindex.any_vecs(),
self.difficultyepoch.any_vecs(),

View File

@@ -2,6 +2,7 @@ use std::path::Path;
use brk_core::{Difficultyepoch, Height};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
@@ -14,6 +15,7 @@ where
T: ComputedType + PartialOrd,
{
pub height: ComputedVec<Height, T>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
}
@@ -36,10 +38,14 @@ where
compressed,
)?;
let height_extra =
ComputedVecBuilder::forced_import(path, name, compressed, options.copy_self_extra())?;
let options = options.remove_percentiles();
Ok(Self {
height,
height_extra,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, compressed, options)?,
})
@@ -47,15 +53,25 @@ where
pub fn compute<F>(
&mut self,
mut compute: F,
indexer: &mut Indexer,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Height, T>) -> Result<()>,
F: FnMut(
&mut ComputedVec<Height, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{
compute(&mut self.height)?;
compute(&mut self.height, indexer, indexes, starting_indexes, exit)?;
self.height_extra
.extend(starting_indexes.height, self.height.mut_vec(), exit)?;
self.difficultyepoch.compute(
starting_indexes.difficultyepoch,
@@ -71,6 +87,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![self.height.any_vec()],
self.height_extra.any_vecs(),
self.difficultyepoch.any_vecs(),
// self.halvingepoch.as_any_vecs(),
]

View File

@@ -18,6 +18,7 @@ where
T: ComputedType + PartialOrd,
{
pub txindex: ComputedVec<Txindex, T>,
pub txindex_extra: ComputedVecBuilder<Txindex, T>,
pub height: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
@@ -47,6 +48,13 @@ where
compressed,
)?;
let txindex_extra = ComputedVecBuilder::forced_import(
path,
name,
compressed,
StorableVecGeneatorOptions::default(),
)?;
let height = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
@@ -54,6 +62,7 @@ where
Ok(Self {
txindex,
txindex_extra,
height,
dateindex,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
@@ -68,16 +77,25 @@ where
pub fn compute<F>(
&mut self,
mut compute: F,
indexer: &mut Indexer,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Txindex, T>) -> Result<()>,
F: FnMut(
&mut ComputedVec<Txindex, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{
compute(&mut self.txindex)?;
compute(&mut self.txindex, indexer, indexes, starting_indexes, exit)?;
self.txindex_extra
.extend(starting_indexes.txindex, self.txindex.mut_vec(), exit)?;
self.height.compute(
starting_indexes.height,
@@ -149,6 +167,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![self.txindex.any_vec()],
self.txindex_extra.any_vecs(),
self.height.any_vecs(),
self.dateindex.any_vecs(),
self.weekindex.any_vecs(),

View File

@@ -55,9 +55,14 @@ impl Vecs {
pub fn forced_import(path: &Path, compressed: Compressed) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
let mut fetched_path = path.to_owned();
fetched_path.pop();
fetched_path.pop();
fetched_path = fetched_path.join("fetched/vecs");
Ok(Self {
dateindex_to_ohlc_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_ohlc_in_cents"),
&fetched_path.join("dateindex_to_ohlc_in_cents"),
Version::ONE,
compressed,
)?,
@@ -87,7 +92,7 @@ impl Vecs {
compressed,
)?,
height_to_ohlc_in_cents: ComputedVec::forced_import(
&path.join("height_to_ohlc_in_cents"),
&fetched_path.join("height_to_ohlc_in_cents"),
Version::ONE,
compressed,
)?,
@@ -328,7 +333,11 @@ impl Vecs {
)?;
self.timeindexes_to_close.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
@@ -336,13 +345,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_high.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
@@ -350,13 +360,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_low.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
@@ -364,13 +375,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_open.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
@@ -378,13 +390,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_close.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
@@ -392,13 +405,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_high.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
@@ -406,13 +420,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_low.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
@@ -420,13 +435,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_open.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
@@ -434,9 +450,6 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.weekindex_to_ohlc.compute_transform(
@@ -720,7 +733,11 @@ impl Vecs {
)?;
self.chainindexes_to_sats_per_dollar.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
self.chainindexes_to_close.height.mut_vec(),
@@ -728,13 +745,14 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_sats_per_dollar.compute(
|v| {
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.dateindex,
self.timeindexes_to_close.dateindex.mut_vec(),
@@ -742,9 +760,6 @@ impl Vecs {
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
Ok(())

View File

@@ -1,11 +1,15 @@
use std::{fs, path::Path};
use brk_core::Txindex;
use brk_core::{CounterU64, Txindex};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{ComputedVec, Indexes, indexes};
use super::{
ComputedVec, Indexes,
grouped::{ComputedVecsFromTxindex, StorableVecGeneatorOptions},
indexes,
};
#[derive(Clone)]
pub struct Vecs {
@@ -21,9 +25,9 @@ pub struct Vecs {
// pub txindex_to_fee: ComputedVec<Txindex, Sats>,
pub txindex_to_is_coinbase: ComputedVec<Txindex, bool>,
// pub txindex_to_feerate: ComputedVec<Txindex, Feerate>,
pub txindex_to_inputs_count: ComputedVec<Txindex, u32>,
pub txindex_to_inputs_count: ComputedVecsFromTxindex<CounterU64>,
// pub txindex_to_inputs_sum: ComputedVec<Txindex, Sats>,
pub txindex_to_outputs_count: ComputedVec<Txindex, u32>,
pub txindex_to_outputs_count: ComputedVecsFromTxindex<CounterU64>,
// pub txindex_to_outputs_sum: ComputedVec<Txindex, Sats>,
// pub txinindex_to_value: ComputedVec<Txinindex, Sats>,
}
@@ -58,24 +62,20 @@ impl Vecs {
compressed,
)?,
// txindex_to_feerate: StorableVec::forced_import(&path.join("txindex_to_feerate"), Version::ONE)?,
txindex_to_inputs_count: ComputedVec::forced_import(
&path.join("txindex_to_inputs_count"),
txindex_to_inputs_count: ComputedVecsFromTxindex::forced_import(
path,
"inputs_count",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?,
// txindex_to_inputs_sum: StorableVec::forced_import(
// &path.join("txindex_to_inputs_sum"),
// Version::ONE,
// )?,
txindex_to_outputs_count: ComputedVec::forced_import(
&path.join("txindex_to_outputs_count"),
txindex_to_outputs_count: ComputedVecsFromTxindex::forced_import(
path,
"outputs_count",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?,
// txindex_to_outputs_sum: StorableVec::forced_import(
// &path.join("txindex_to_outputs_sum"),
// Version::ONE,
// )?,
// txinindex_to_value: StorableVec::forced_import(
// &path.join("txinindex_to_value"),
// Version::ONE,
@@ -91,22 +91,52 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
self.txindex_to_inputs_count.compute(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, indexes, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
indexer.mut_vecs().txindex_to_first_txinindex.mut_vec(),
indexes.txindex_to_last_txinindex.mut_vec(),
exit,
)
},
)?;
self.txindex_to_outputs_count.compute(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, indexes, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
indexer.mut_vecs().txindex_to_first_txoutindex.mut_vec(),
indexes.txindex_to_last_txoutindex.mut_vec(),
exit,
)
},
)?;
// self.txindex_to_inputs_count.compute_count_from_indexes(
// starting_indexes.txindex,
// indexer_vecs.txindex_to_first_txinindex.mut_vec(),
// indexes.txindex_to_last_txinindex.mut_vec(),
// exit,
// )?;
// self.txindex_to_outputs_count.compute_count_from_indexes(
// starting_indexes.txindex,
// indexer_vecs.txindex_to_first_txoutindex.mut_vec(),
// indexes.txindex_to_last_txoutindex.mut_vec(),
// exit,
// )?;
let indexer_vecs = indexer.mut_vecs();
self.txindex_to_inputs_count.compute_count_from_indexes(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txinindex.mut_vec(),
indexes.txindex_to_last_txinindex.mut_vec(),
exit,
)?;
self.txindex_to_outputs_count.compute_count_from_indexes(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txoutindex.mut_vec(),
indexes.txindex_to_last_txoutindex.mut_vec(),
exit,
)?;
self.txindex_to_is_coinbase.compute_is_first_ordered(
starting_indexes.txindex,
indexer_vecs.txindex_to_height.mut_vec(),
@@ -135,31 +165,15 @@ impl Vecs {
// &mut indexer.vecs().height_to_first_txindex,
// )?;
// self.vecs.height_to_dateindex.compute(...)
// ---
// Date to X
// ---
// ...
// ---
// Month to X
// ---
// ...
// ---
// Year to X
// ---
// ...
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
vec![
self.txindex_to_is_coinbase.any_vec(),
self.txindex_to_inputs_count.any_vec(),
self.txindex_to_outputs_count.any_vec(),
[
vec![self.txindex_to_is_coinbase.any_vec()],
self.txindex_to_outputs_count.any_vecs(),
self.txindex_to_inputs_count.any_vecs(),
]
.concat()
}
}