mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-02 18:40:00 -07:00
global: snapshot
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_error::{Error, Result};
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{CheckedSub, StoredU64, Version};
|
||||
@@ -11,7 +10,7 @@ use crate::utils::get_percentile;
|
||||
|
||||
use super::ComputedType;
|
||||
|
||||
#[derive(Clone, Debug, Traversable, Allocative)]
|
||||
#[derive(Clone, Debug, Traversable)]
|
||||
pub struct EagerVecsBuilder<I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
@@ -219,11 +218,11 @@ where
|
||||
let cumulative_vec = self.cumulative.as_mut().unwrap();
|
||||
|
||||
let mut cumulative = index.decremented().map_or(T::from(0_usize), |index| {
|
||||
cumulative_vec.iter().unsafe_get(index)
|
||||
cumulative_vec.iter().get_unwrap(index)
|
||||
});
|
||||
source
|
||||
.iter()
|
||||
.skip(index)
|
||||
.skip(index.to_usize())
|
||||
.enumerate()
|
||||
.try_for_each(|(i, v)| -> Result<()> {
|
||||
cumulative += v;
|
||||
@@ -260,17 +259,20 @@ where
|
||||
|
||||
let mut cumulative = cumulative_vec.map(|cumulative_vec| {
|
||||
index.decremented().map_or(T::from(0_usize), |index| {
|
||||
cumulative_vec.iter().unsafe_get(index)
|
||||
cumulative_vec.iter().get_unwrap(index)
|
||||
})
|
||||
});
|
||||
|
||||
first_indexes.iter().skip(index).enumerate().try_for_each(
|
||||
|(index, first_index)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.unsafe_get(index);
|
||||
first_indexes
|
||||
.iter()
|
||||
.skip(index.to_usize())
|
||||
.enumerate()
|
||||
.try_for_each(|(index, first_index)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.get_at_unwrap(index);
|
||||
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
let f = source_iter
|
||||
.get_inner(first_index)
|
||||
.get(first_index)
|
||||
.unwrap_or_else(|| T::from(0_usize));
|
||||
first.forced_push_at(index, f, exit)?;
|
||||
}
|
||||
@@ -281,7 +283,7 @@ where
|
||||
panic!("should compute last if count can be 0")
|
||||
}
|
||||
let last_index = first_index + (count_index - 1);
|
||||
let v = source_iter.unsafe_get(last_index);
|
||||
let v = source_iter.get_unwrap(last_index);
|
||||
// .context("to work")
|
||||
// .inspect_err(|_| {
|
||||
// dbg!(first_index, count_index, last_index);
|
||||
@@ -304,10 +306,9 @@ where
|
||||
let needs_values = needs_sorted || needs_average_sum_or_cumulative;
|
||||
|
||||
if needs_values {
|
||||
source_iter.set(first_index);
|
||||
source_iter.set_position(first_index);
|
||||
let mut values = (&mut source_iter)
|
||||
.take(*count_index as usize)
|
||||
.map(|(_, v)| v)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if needs_sorted {
|
||||
@@ -385,8 +386,7 @@ where
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)?;
|
||||
|
||||
@@ -431,16 +431,19 @@ where
|
||||
|
||||
let mut cumulative = self.cumulative.as_mut().map(|cumulative_vec| {
|
||||
index.decremented().map_or(T::from(0_usize), |index| {
|
||||
cumulative_vec.iter().unsafe_get(index)
|
||||
cumulative_vec.iter().get_unwrap(index)
|
||||
})
|
||||
});
|
||||
|
||||
first_indexes.iter().skip(index).enumerate().try_for_each(
|
||||
|(index, first_index, ..)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.unsafe_get(index);
|
||||
first_indexes
|
||||
.iter()
|
||||
.skip(index.to_usize())
|
||||
.enumerate()
|
||||
.try_for_each(|(index, first_index, ..)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.get_at_unwrap(index);
|
||||
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
let v = source_first_iter.as_mut().unwrap().unsafe_get(first_index);
|
||||
let v = source_first_iter.as_mut().unwrap().get_unwrap(first_index);
|
||||
first.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
|
||||
@@ -450,7 +453,7 @@ where
|
||||
panic!("should compute last if count can be 0")
|
||||
}
|
||||
let last_index = first_index + (count_index - 1);
|
||||
let v = source_last_iter.as_mut().unwrap().unsafe_get(last_index);
|
||||
let v = source_last_iter.as_mut().unwrap().get_unwrap(last_index);
|
||||
last.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
|
||||
@@ -464,10 +467,9 @@ where
|
||||
if needs_sorted {
|
||||
if let Some(max) = self.max.as_mut() {
|
||||
let source_max_iter = source_max_iter.as_mut().unwrap();
|
||||
source_max_iter.set(first_index);
|
||||
source_max_iter.set_position(first_index);
|
||||
let mut values = source_max_iter
|
||||
.take(*count_index as usize)
|
||||
.map(|(_, v)| v)
|
||||
.collect::<Vec<_>>();
|
||||
values.sort_unstable();
|
||||
max.forced_push_at(index, *values.last().unwrap(), exit)?;
|
||||
@@ -475,10 +477,9 @@ where
|
||||
|
||||
if let Some(min) = self.min.as_mut() {
|
||||
let source_min_iter = source_min_iter.as_mut().unwrap();
|
||||
source_min_iter.set(first_index);
|
||||
source_min_iter.set_position(first_index);
|
||||
let mut values = source_min_iter
|
||||
.take(*count_index as usize)
|
||||
.map(|(_, v)| v)
|
||||
.collect::<Vec<_>>();
|
||||
values.sort_unstable();
|
||||
min.forced_push_at(index, *values.first().unwrap(), exit)?;
|
||||
@@ -488,10 +489,9 @@ where
|
||||
if needs_average_sum_or_cumulative {
|
||||
if let Some(average) = self.average.as_mut() {
|
||||
let source_average_iter = source_average_iter.as_mut().unwrap();
|
||||
source_average_iter.set(first_index);
|
||||
source_average_iter.set_position(first_index);
|
||||
let values = source_average_iter
|
||||
.take(*count_index as usize)
|
||||
.map(|(_, v)| v)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let len = values.len();
|
||||
@@ -504,10 +504,9 @@ where
|
||||
|
||||
if needs_sum_or_cumulative {
|
||||
let source_sum_iter = source_sum_iter.as_mut().unwrap();
|
||||
source_sum_iter.set(first_index);
|
||||
source_sum_iter.set_position(first_index);
|
||||
let values = source_sum_iter
|
||||
.take(*count_index as usize)
|
||||
.map(|(_, v)| v)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
|
||||
@@ -526,8 +525,7 @@ where
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)?;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Version;
|
||||
use vecdb::{
|
||||
@@ -10,7 +9,7 @@ use crate::grouped::{EagerVecsBuilder, VecBuilderOptions};
|
||||
use super::ComputedType;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[derive(Clone, Traversable, Allocative)]
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyVecsBuilder<I, T, S1I, S2T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
@@ -71,7 +70,7 @@ where
|
||||
if i.to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
source.next_at(S1I::min_from(i)).map(|(_, v)| v)
|
||||
source.get_at(S1I::min_from(i))
|
||||
},
|
||||
))
|
||||
}),
|
||||
@@ -96,9 +95,7 @@ where
|
||||
if i.to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
source
|
||||
.next_at(S1I::max_from(i, source.len()))
|
||||
.map(|(_, v)| v)
|
||||
source.get_at(S1I::max_from(i, source.len()))
|
||||
},
|
||||
))
|
||||
}),
|
||||
@@ -116,7 +113,7 @@ where
|
||||
return None;
|
||||
}
|
||||
S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, v)| v))
|
||||
.flat_map(|i| source.get_at(i))
|
||||
.min()
|
||||
},
|
||||
))
|
||||
@@ -135,7 +132,7 @@ where
|
||||
return None;
|
||||
}
|
||||
S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, v)| v))
|
||||
.flat_map(|i| source.get_at(i))
|
||||
.max()
|
||||
},
|
||||
))
|
||||
@@ -154,7 +151,7 @@ where
|
||||
return None;
|
||||
}
|
||||
let vec = S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, v)| v))
|
||||
.flat_map(|i| source.get_at(i))
|
||||
.collect::<Vec<_>>();
|
||||
if vec.is_empty() {
|
||||
return None;
|
||||
@@ -184,7 +181,7 @@ where
|
||||
return None;
|
||||
}
|
||||
let vec = S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, v)| v))
|
||||
.flat_map(|i| source.get_at(i))
|
||||
.collect::<Vec<_>>();
|
||||
if vec.is_empty() {
|
||||
return None;
|
||||
@@ -205,9 +202,7 @@ where
|
||||
if i.to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
source
|
||||
.next_at(S1I::max_from(i, source.len()))
|
||||
.map(|(_, v)| v)
|
||||
source.get_at(S1I::max_from(i, source.len()))
|
||||
},
|
||||
))
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_error::Result;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
@@ -11,7 +10,7 @@ use crate::{Indexes, grouped::LazyVecsBuilder, indexes};
|
||||
|
||||
use super::{ComputedType, EagerVecsBuilder, Source, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone, Allocative)]
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromDateIndex<T>
|
||||
where
|
||||
T: ComputedType + PartialOrd,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_error::Result;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
@@ -16,7 +15,7 @@ use crate::{
|
||||
|
||||
use super::{ComputedType, EagerVecsBuilder, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone, Allocative)]
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromHeight<T>
|
||||
where
|
||||
T: ComputedType + PartialOrd,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -8,7 +7,7 @@ use brk_types::{
|
||||
};
|
||||
use vecdb::{
|
||||
AnyCloneableIterableVec, AnyVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec,
|
||||
StoredIndex, VecIterator,
|
||||
StoredIndex, VecIteratorExtended,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -19,7 +18,7 @@ use crate::{
|
||||
|
||||
use super::{ComputedType, EagerVecsBuilder, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone, Allocative)]
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromTxindex<T>
|
||||
where
|
||||
T: ComputedType + PartialOrd,
|
||||
@@ -253,90 +252,90 @@ impl ComputedVecsFromTxindex<Bitcoin> {
|
||||
.map(Height::from)
|
||||
.try_for_each(|height| -> Result<()> {
|
||||
if let Some(first) = self.height.first.as_mut() {
|
||||
first.forced_push_at(
|
||||
first.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_first().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_first().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(average) = self.height.average.as_mut() {
|
||||
average.forced_push_at(
|
||||
average.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_average().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_average().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(sum) = self.height.sum.as_mut() {
|
||||
sum.forced_push_at(
|
||||
sum.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_sum().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_sum().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(max) = self.height.max.as_mut() {
|
||||
max.forced_push_at(
|
||||
max.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_max().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_max().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct90) = self.height.pct90.as_mut() {
|
||||
pct90.forced_push_at(
|
||||
pct90.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_pct90().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_pct90().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct75) = self.height.pct75.as_mut() {
|
||||
pct75.forced_push_at(
|
||||
pct75.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_pct75().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_pct75().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(median) = self.height.median.as_mut() {
|
||||
median.forced_push_at(
|
||||
median.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_median().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_median().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct25) = self.height.pct25.as_mut() {
|
||||
pct25.forced_push_at(
|
||||
pct25.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_pct25().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_pct25().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct10) = self.height.pct10.as_mut() {
|
||||
pct10.forced_push_at(
|
||||
pct10.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_pct10().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_pct10().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(min) = self.height.min.as_mut() {
|
||||
min.forced_push_at(
|
||||
min.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_min().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_min().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(last) = self.height.last.as_mut() {
|
||||
last.forced_push_at(
|
||||
last.forced_push(
|
||||
height,
|
||||
Bitcoin::from(sats.height.unwrap_last().into_iter().unsafe_get(height)),
|
||||
Bitcoin::from(sats.height.unwrap_last().into_iter().get_unwrap(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(cumulative) = self.height.cumulative.as_mut() {
|
||||
cumulative.forced_push_at(
|
||||
cumulative.forced_push(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_cumulative()
|
||||
.into_iter()
|
||||
.unsafe_get(height),
|
||||
.get_unwrap(height),
|
||||
),
|
||||
exit,
|
||||
)?;
|
||||
@@ -378,104 +377,104 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
(starting_index.to_usize()..indexer.vecs.height_to_weight.len())
|
||||
.map(Height::from)
|
||||
.try_for_each(|height| -> Result<()> {
|
||||
let price = *close_iter.unsafe_get(height);
|
||||
let price = *close_iter.get_unwrap(height);
|
||||
|
||||
if let Some(first) = self.height.first.as_mut() {
|
||||
first.forced_push_at(
|
||||
first.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_first().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_first().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(average) = self.height.average.as_mut() {
|
||||
average.forced_push_at(
|
||||
average.forced_push(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_average()
|
||||
.into_iter()
|
||||
.unsafe_get(height),
|
||||
.get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(sum) = self.height.sum.as_mut() {
|
||||
sum.forced_push_at(
|
||||
sum.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_sum().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_sum().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(max) = self.height.max.as_mut() {
|
||||
max.forced_push_at(
|
||||
max.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_max().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_max().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct90) = self.height.pct90.as_mut() {
|
||||
pct90.forced_push_at(
|
||||
pct90.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_pct90().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_pct90().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct75) = self.height.pct75.as_mut() {
|
||||
pct75.forced_push_at(
|
||||
pct75.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_pct75().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_pct75().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(median) = self.height.median.as_mut() {
|
||||
median.forced_push_at(
|
||||
median.forced_push(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_median()
|
||||
.into_iter()
|
||||
.unsafe_get(height),
|
||||
.get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct25) = self.height.pct25.as_mut() {
|
||||
pct25.forced_push_at(
|
||||
pct25.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_pct25().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_pct25().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct10) = self.height.pct10.as_mut() {
|
||||
pct10.forced_push_at(
|
||||
pct10.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_pct10().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_pct10().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(min) = self.height.min.as_mut() {
|
||||
min.forced_push_at(
|
||||
min.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_min().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_min().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(last) = self.height.last.as_mut() {
|
||||
last.forced_push_at(
|
||||
last.forced_push(
|
||||
height,
|
||||
price * bitcoin.height.unwrap_last().into_iter().unsafe_get(height),
|
||||
price * bitcoin.height.unwrap_last().into_iter().get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(cumulative) = self.height.cumulative.as_mut() {
|
||||
cumulative.forced_push_at(
|
||||
cumulative.forced_push(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_cumulative()
|
||||
.into_iter()
|
||||
.unsafe_get(height),
|
||||
.get_unwrap(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Date, DateIndex, Dollars, StoredF32, Version};
|
||||
use vecdb::{
|
||||
AnyIterableVec, AnyStoredVec, AnyVec, CollectableVec, Database, EagerVec, Exit,
|
||||
GenericStoredVec, StoredIndex, VecIterator,
|
||||
GenericStoredVec, StoredIndex, VecIteratorExtended,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -383,8 +383,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.unwrap()
|
||||
.min(starting_indexes.dateindex);
|
||||
|
||||
let min_ratio_date_usize = min_ratio_date.to_usize();
|
||||
|
||||
let mut sorted = self.ratio.dateindex.as_ref().unwrap().collect_range(
|
||||
Some(min_ratio_date.to_usize()),
|
||||
Some(min_ratio_date_usize),
|
||||
Some(starting_dateindex.to_usize()),
|
||||
);
|
||||
|
||||
@@ -395,10 +397,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.skip(starting_dateindex)
|
||||
.skip(starting_dateindex.to_usize())
|
||||
.enumerate()
|
||||
.try_for_each(|(index, ratio)| -> Result<()> {
|
||||
if index < min_ratio_date {
|
||||
if index < min_ratio_date_usize {
|
||||
self.ratio_pct5
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -547,7 +549,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
starting_indexes.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unsafe_get(i);
|
||||
let multiplier = iter.get_unwrap(i);
|
||||
(i, price * multiplier)
|
||||
},
|
||||
exit,
|
||||
@@ -564,7 +566,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
starting_indexes.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unsafe_get(i);
|
||||
let multiplier = iter.get_unwrap(i);
|
||||
(i, price * multiplier)
|
||||
},
|
||||
exit,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{CheckedSub, Date, DateIndex, Dollars, StoredF32, Version};
|
||||
use brk_types::{Date, DateIndex, Dollars, StoredF32, Version};
|
||||
use vecdb::{
|
||||
AnyIterableVec, AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec,
|
||||
Exit, GenericStoredVec, StoredIndex,
|
||||
@@ -498,12 +498,14 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
let mut m2_5sd = self.m2_5sd.as_mut().map(|c| c.dateindex.as_mut().unwrap());
|
||||
let mut m3sd = self.m3sd.as_mut().map(|c| c.dateindex.as_mut().unwrap());
|
||||
|
||||
let min_date_usize = min_date.to_usize();
|
||||
|
||||
source
|
||||
.iter()
|
||||
.skip(starting_dateindex)
|
||||
.skip(starting_dateindex.to_usize())
|
||||
.enumerate()
|
||||
.try_for_each(|(index, ratio)| -> Result<()> {
|
||||
if index < min_date {
|
||||
if index < min_date_usize {
|
||||
self.sd.dateindex.as_mut().unwrap().forced_push_at(
|
||||
index,
|
||||
StoredF32::NAN,
|
||||
@@ -550,9 +552,10 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
|
||||
sorted.insert(pos, ratio);
|
||||
|
||||
let avg = sma_iter.unsafe_get(index);
|
||||
let avg = sma_iter.get_at_unwrap(index);
|
||||
|
||||
let population = index.checked_sub(min_date).unwrap().to_usize() as f32 + 1.0;
|
||||
let population =
|
||||
index.checked_sub(min_date_usize).unwrap().to_usize() as f32 + 1.0;
|
||||
|
||||
let sd = StoredF32::from(
|
||||
(sorted.iter().map(|v| (**v - *avg).powi(2)).sum::<f32>() / population)
|
||||
@@ -639,7 +642,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
starting_indexes.dateindex,
|
||||
price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unsafe_get(i);
|
||||
let multiplier = iter.get_unwrap(i);
|
||||
(i, price * multiplier)
|
||||
},
|
||||
exit,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Height, Sats, Version};
|
||||
@@ -13,7 +12,7 @@ use crate::{
|
||||
|
||||
use super::{ComputedVecsFromHeight, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone, Traversable, Allocative)]
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ComputedValueVecsFromHeight {
|
||||
pub sats: ComputedVecsFromHeight<Sats>,
|
||||
pub bitcoin: ComputedVecsFromHeight<Bitcoin>,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use allocative::Allocative;
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -12,7 +11,7 @@ use crate::{Indexes, grouped::Source, indexes, price};
|
||||
|
||||
use super::{ComputedVecsFromTxindex, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone, Traversable, Allocative)]
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct ComputedValueVecsFromTxindex {
|
||||
pub sats: ComputedVecsFromTxindex<Sats>,
|
||||
pub bitcoin_txindex: LazyVecFrom1<TxIndex, Bitcoin, TxIndex, Sats>,
|
||||
@@ -59,8 +58,8 @@ impl ComputedValueVecsFromTxindex {
|
||||
version + VERSION,
|
||||
source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
|
||||
|txindex: TxIndex, iter| {
|
||||
iter.next_at(txindex.to_usize())
|
||||
.map(|(_, sats)| Bitcoin::from(sats))
|
||||
iter.get_at(txindex.to_usize())
|
||||
.map(|sats| Bitcoin::from(sats))
|
||||
},
|
||||
);
|
||||
|
||||
@@ -85,14 +84,12 @@ impl ComputedValueVecsFromTxindex {
|
||||
txindex_to_height_iter,
|
||||
height_to_price_close_iter| {
|
||||
let txindex = txindex.to_usize();
|
||||
txindex_to_btc_iter.next_at(txindex).and_then(|(_, btc)| {
|
||||
txindex_to_height_iter
|
||||
.next_at(txindex)
|
||||
.and_then(|(_, height)| {
|
||||
height_to_price_close_iter
|
||||
.next_at(height.to_usize())
|
||||
.map(|(_, close)| *close * btc)
|
||||
})
|
||||
txindex_to_btc_iter.get_at(txindex).and_then(|btc| {
|
||||
txindex_to_height_iter.get_at(txindex).and_then(|height| {
|
||||
height_to_price_close_iter
|
||||
.get_at(height.to_usize())
|
||||
.map(|close| *close * btc)
|
||||
})
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user