mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-02 18:40:00 -07:00
global: snapshot
This commit is contained in:
@@ -219,13 +219,17 @@ where
|
||||
let cumulative_vec = self.cumulative.as_mut().unwrap();
|
||||
|
||||
let mut cumulative = index.decremented().map_or(T::from(0_usize), |index| {
|
||||
cumulative_vec.iter().unwrap_get_inner(index)
|
||||
cumulative_vec.iter().unsafe_get(index)
|
||||
});
|
||||
source.iter_at(index).try_for_each(|(i, v)| -> Result<()> {
|
||||
cumulative += v;
|
||||
cumulative_vec.forced_push_at(i, cumulative, exit)?;
|
||||
Ok(())
|
||||
})?;
|
||||
source
|
||||
.iter()
|
||||
.skip(index)
|
||||
.enumerate()
|
||||
.try_for_each(|(i, v)| -> Result<()> {
|
||||
cumulative += v;
|
||||
cumulative_vec.forced_push_at(i, cumulative, exit)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)?;
|
||||
|
||||
@@ -256,14 +260,13 @@ where
|
||||
|
||||
let mut cumulative = cumulative_vec.map(|cumulative_vec| {
|
||||
index.decremented().map_or(T::from(0_usize), |index| {
|
||||
cumulative_vec.iter().unwrap_get_inner(index)
|
||||
cumulative_vec.iter().unsafe_get(index)
|
||||
})
|
||||
});
|
||||
|
||||
first_indexes
|
||||
.iter_at(index)
|
||||
.try_for_each(|(index, first_index)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.unwrap_get_inner(index);
|
||||
first_indexes.iter().skip(index).enumerate().try_for_each(
|
||||
|(index, first_index)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.unsafe_get(index);
|
||||
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
let f = source_iter
|
||||
@@ -278,7 +281,7 @@ where
|
||||
panic!("should compute last if count can be 0")
|
||||
}
|
||||
let last_index = first_index + (count_index - 1);
|
||||
let v = source_iter.unwrap_get_inner(last_index);
|
||||
let v = source_iter.unsafe_get(last_index);
|
||||
// .context("to work")
|
||||
// .inspect_err(|_| {
|
||||
// dbg!(first_index, count_index, last_index);
|
||||
@@ -382,7 +385,8 @@ where
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
self.safe_flush(exit)?;
|
||||
|
||||
@@ -427,20 +431,16 @@ where
|
||||
|
||||
let mut cumulative = self.cumulative.as_mut().map(|cumulative_vec| {
|
||||
index.decremented().map_or(T::from(0_usize), |index| {
|
||||
cumulative_vec.iter().unwrap_get_inner(index)
|
||||
cumulative_vec.iter().unsafe_get(index)
|
||||
})
|
||||
});
|
||||
|
||||
first_indexes
|
||||
.iter_at(index)
|
||||
.try_for_each(|(index, first_index, ..)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.unwrap_get_inner(index);
|
||||
first_indexes.iter().skip(index).enumerate().try_for_each(
|
||||
|(index, first_index, ..)| -> Result<()> {
|
||||
let count_index = count_indexes_iter.unsafe_get(index);
|
||||
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
let v = source_first_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.unwrap_get_inner(first_index);
|
||||
let v = source_first_iter.as_mut().unwrap().unsafe_get(first_index);
|
||||
first.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
|
||||
@@ -450,10 +450,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()
|
||||
.unwrap_get_inner(last_index);
|
||||
let v = source_last_iter.as_mut().unwrap().unsafe_get(last_index);
|
||||
last.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
|
||||
@@ -529,7 +526,8 @@ where
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
self.safe_flush(exit)?;
|
||||
|
||||
|
||||
@@ -255,132 +255,77 @@ impl ComputedVecsFromTxindex<Bitcoin> {
|
||||
if let Some(first) = self.height.first.as_mut() {
|
||||
first.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_first()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_first().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(average) = self.height.average.as_mut() {
|
||||
average.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_average()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_average().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(sum) = self.height.sum.as_mut() {
|
||||
sum.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_sum()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_sum().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(max) = self.height.max.as_mut() {
|
||||
max.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_max()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_max().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct90) = self.height.pct90.as_mut() {
|
||||
pct90.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_pct90()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_pct90().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct75) = self.height.pct75.as_mut() {
|
||||
pct75.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_pct75()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_pct75().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(median) = self.height.median.as_mut() {
|
||||
median.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_median()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_median().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct25) = self.height.pct25.as_mut() {
|
||||
pct25.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_pct25()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_pct25().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct10) = self.height.pct10.as_mut() {
|
||||
pct10.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_pct10()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_pct10().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(min) = self.height.min.as_mut() {
|
||||
min.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_min()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_min().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(last) = self.height.last.as_mut() {
|
||||
last.forced_push_at(
|
||||
height,
|
||||
Bitcoin::from(
|
||||
sats.height
|
||||
.unwrap_last()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
),
|
||||
Bitcoin::from(sats.height.unwrap_last().into_iter().unsafe_get(height)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
@@ -391,7 +336,7 @@ impl ComputedVecsFromTxindex<Bitcoin> {
|
||||
sats.height
|
||||
.unwrap_cumulative()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
.unsafe_get(height),
|
||||
),
|
||||
exit,
|
||||
)?;
|
||||
@@ -433,17 +378,12 @@ 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.unwrap_get_inner(height);
|
||||
let price = *close_iter.unsafe_get(height);
|
||||
|
||||
if let Some(first) = self.height.first.as_mut() {
|
||||
first.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_first()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_first().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
@@ -455,55 +395,35 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
.height
|
||||
.unwrap_average()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
.unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(sum) = self.height.sum.as_mut() {
|
||||
sum.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_sum()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_sum().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(max) = self.height.max.as_mut() {
|
||||
max.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_max()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_max().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct90) = self.height.pct90.as_mut() {
|
||||
pct90.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_pct90()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_pct90().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct75) = self.height.pct75.as_mut() {
|
||||
pct75.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_pct75()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_pct75().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
@@ -515,55 +435,35 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
.height
|
||||
.unwrap_median()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
.unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct25) = self.height.pct25.as_mut() {
|
||||
pct25.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_pct25()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_pct25().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(pct10) = self.height.pct10.as_mut() {
|
||||
pct10.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_pct10()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_pct10().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(min) = self.height.min.as_mut() {
|
||||
min.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_min()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_min().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
if let Some(last) = self.height.last.as_mut() {
|
||||
last.forced_push_at(
|
||||
height,
|
||||
price
|
||||
* bitcoin
|
||||
.height
|
||||
.unwrap_last()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
price * bitcoin.height.unwrap_last().into_iter().unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
@@ -575,7 +475,7 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
.height
|
||||
.unwrap_cumulative()
|
||||
.into_iter()
|
||||
.unwrap_get_inner(height),
|
||||
.unsafe_get(height),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -394,7 +394,9 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter_at(starting_dateindex)
|
||||
.iter()
|
||||
.skip(starting_dateindex)
|
||||
.enumerate()
|
||||
.try_for_each(|(index, ratio)| -> Result<()> {
|
||||
if index < min_ratio_date {
|
||||
self.ratio_pct5
|
||||
@@ -545,7 +547,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
starting_indexes.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
let multiplier = iter.unsafe_get(i);
|
||||
(i, price * multiplier)
|
||||
},
|
||||
exit,
|
||||
@@ -562,7 +564,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
starting_indexes.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
let multiplier = iter.unsafe_get(i);
|
||||
(i, price * multiplier)
|
||||
},
|
||||
exit,
|
||||
|
||||
@@ -499,7 +499,9 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
let mut m3sd = self.m3sd.as_mut().map(|c| c.dateindex.as_mut().unwrap());
|
||||
|
||||
source
|
||||
.iter_at(starting_dateindex)
|
||||
.iter()
|
||||
.skip(starting_dateindex)
|
||||
.enumerate()
|
||||
.try_for_each(|(index, ratio)| -> Result<()> {
|
||||
if index < min_date {
|
||||
self.sd.dateindex.as_mut().unwrap().forced_push_at(
|
||||
@@ -548,7 +550,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
|
||||
sorted.insert(pos, ratio);
|
||||
|
||||
let avg = sma_iter.unwrap_get_inner(index);
|
||||
let avg = sma_iter.unsafe_get(index);
|
||||
|
||||
let population = index.checked_sub(min_date).unwrap().to_usize() as f32 + 1.0;
|
||||
|
||||
@@ -637,7 +639,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
starting_indexes.dateindex,
|
||||
price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
let multiplier = iter.unsafe_get(i);
|
||||
(i, price * multiplier)
|
||||
},
|
||||
exit,
|
||||
|
||||
Reference in New Issue
Block a user