computer: part 3

This commit is contained in:
nym21
2025-03-21 11:45:23 +01:00
parent 5a94b6b56c
commit a9929438cd
11 changed files with 876 additions and 68 deletions

View File

@@ -7,13 +7,13 @@ use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{
Indexes, StorableVec, indexes,
stats::{StorableVecGeneatorByIndex, StorableVecGeneatorOptions},
stats::{StorableVecGeneatorOptions, StorableVecsStatsFromHeight},
};
#[derive(Clone)]
pub struct Vecs {
pub height_to_block_interval: StorableVec<Height, Timestamp>,
pub indexes_to_block_interval_stats: StorableVecGeneatorByIndex<Timestamp>,
pub indexes_to_block_interval_stats: StorableVecsStatsFromHeight<Timestamp>,
pub dateindex_to_block_count: StorableVec<Dateindex, u16>,
pub dateindex_to_total_block_count: StorableVec<Dateindex, u32>,
}
@@ -28,7 +28,7 @@ impl Vecs {
Version::from(1),
compressed,
)?,
indexes_to_block_interval_stats: StorableVecGeneatorByIndex::forced_import(
indexes_to_block_interval_stats: StorableVecsStatsFromHeight::forced_import(
&path.join("block_interval"),
compressed,
StorableVecGeneatorOptions::default()
@@ -64,12 +64,10 @@ impl Vecs {
|(height, timestamp, _, height_to_timestamp)| {
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
let prev_timestamp = *height_to_timestamp.get(prev_h).unwrap().unwrap();
dbg!((timestamp, prev_timestamp));
timestamp
.checked_sub(prev_timestamp)
.unwrap_or(Timestamp::ZERO)
});
dbg!((height, interval));
(height, interval)
},
exit,

View File

@@ -1,39 +1,61 @@
use std::{fs, path::Path};
use brk_core::{
Cents, Close, Dateindex, Dollars, Height, High, Low, OHLCCents, OHLCDollars, Open, Sats,
Cents, Close, Dateindex, Decadeindex, Difficultyepoch, Dollars, Height, High, Low, Monthindex,
OHLCCents, OHLCDollars, Open, Sats, Weekindex, Yearindex,
};
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{Indexes, StorableVec, indexes};
use super::{
Indexes, StorableVec, indexes,
stats::{
StorableVecGeneatorOptions, StorableVecsStatsFromDate, StorableVecsStatsFromHeightStrict,
},
};
#[derive(Clone)]
pub struct Vecs {
pub dateindex_to_ohlc_in_cents: StorableVec<Dateindex, OHLCCents>,
pub dateindex_to_ohlc: StorableVec<Dateindex, OHLCDollars>,
pub dateindex_to_close_in_cents: StorableVec<Dateindex, Close<Cents>>,
pub dateindex_to_close: StorableVec<Dateindex, Close<Dollars>>,
pub dateindex_to_high_in_cents: StorableVec<Dateindex, High<Cents>>,
pub dateindex_to_close_in_cents: StorableVec<Dateindex, Close<Cents>>,
pub dateindex_to_high: StorableVec<Dateindex, High<Dollars>>,
pub dateindex_to_low_in_cents: StorableVec<Dateindex, Low<Cents>>,
pub dateindex_to_high_in_cents: StorableVec<Dateindex, High<Cents>>,
pub dateindex_to_low: StorableVec<Dateindex, Low<Dollars>>,
pub dateindex_to_open_in_cents: StorableVec<Dateindex, Open<Cents>>,
pub dateindex_to_low_in_cents: StorableVec<Dateindex, Low<Cents>>,
pub dateindex_to_ohlc: StorableVec<Dateindex, OHLCDollars>,
pub dateindex_to_ohlc_in_cents: StorableVec<Dateindex, OHLCCents>,
pub dateindex_to_open: StorableVec<Dateindex, Open<Dollars>>,
pub dateindex_to_open_in_cents: StorableVec<Dateindex, Open<Cents>>,
pub dateindex_to_sats_per_dollar: StorableVec<Dateindex, Close<Sats>>,
pub height_to_ohlc_in_cents: StorableVec<Height, OHLCCents>,
pub height_to_ohlc: StorableVec<Height, OHLCDollars>,
pub height_to_close_in_cents: StorableVec<Height, Close<Cents>>,
pub height_to_close: StorableVec<Height, Close<Dollars>>,
pub height_to_high_in_cents: StorableVec<Height, High<Cents>>,
pub height_to_close_in_cents: StorableVec<Height, Close<Cents>>,
pub height_to_high: StorableVec<Height, High<Dollars>>,
pub height_to_low_in_cents: StorableVec<Height, Low<Cents>>,
pub height_to_high_in_cents: StorableVec<Height, High<Cents>>,
pub height_to_low: StorableVec<Height, Low<Dollars>>,
pub height_to_open_in_cents: StorableVec<Height, Open<Cents>>,
pub height_to_low_in_cents: StorableVec<Height, Low<Cents>>,
pub height_to_ohlc: StorableVec<Height, OHLCDollars>,
pub height_to_ohlc_in_cents: StorableVec<Height, OHLCCents>,
pub height_to_open: StorableVec<Height, Open<Dollars>>,
pub height_to_open_in_cents: StorableVec<Height, Open<Cents>>,
pub height_to_sats_per_dollar: StorableVec<Height, Close<Sats>>,
pub timeindexes_to_close: StorableVecsStatsFromDate<Close<Dollars>>,
pub timeindexes_to_high: StorableVecsStatsFromDate<High<Dollars>>,
pub timeindexes_to_low: StorableVecsStatsFromDate<Low<Dollars>>,
pub timeindexes_to_open: StorableVecsStatsFromDate<Open<Dollars>>,
pub timeindexes_to_sats_per_dollar: StorableVecsStatsFromDate<Close<Sats>>,
pub chainindexes_to_close: StorableVecsStatsFromHeightStrict<Close<Dollars>>,
pub chainindexes_to_high: StorableVecsStatsFromHeightStrict<High<Dollars>>,
pub chainindexes_to_low: StorableVecsStatsFromHeightStrict<Low<Dollars>>,
pub chainindexes_to_open: StorableVecsStatsFromHeightStrict<Open<Dollars>>,
pub chainindexes_to_sats_per_dollar: StorableVecsStatsFromHeightStrict<Close<Sats>>,
pub weekindex_to_ohlc: StorableVec<Weekindex, OHLCDollars>,
pub difficultyepoch_to_ohlc: StorableVec<Difficultyepoch, OHLCDollars>,
pub monthindex_to_ohlc: StorableVec<Monthindex, OHLCDollars>,
pub yearindex_to_ohlc: StorableVec<Yearindex, OHLCDollars>,
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
pub decadeindex_to_ohlc: StorableVec<Decadeindex, OHLCDollars>,
}
impl Vecs {
@@ -151,6 +173,82 @@ impl Vecs {
Version::from(1),
compressed,
)?,
timeindexes_to_open: StorableVecsStatsFromDate::forced_import(
&path.join("open"),
compressed,
StorableVecGeneatorOptions::default().add_first(),
)?,
timeindexes_to_high: StorableVecsStatsFromDate::forced_import(
&path.join("high"),
compressed,
StorableVecGeneatorOptions::default().add_max(),
)?,
timeindexes_to_low: StorableVecsStatsFromDate::forced_import(
&path.join("low"),
compressed,
StorableVecGeneatorOptions::default().add_min(),
)?,
timeindexes_to_close: StorableVecsStatsFromDate::forced_import(
&path.join("close"),
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
timeindexes_to_sats_per_dollar: StorableVecsStatsFromDate::forced_import(
&path.join("sats_per_dollar"),
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
chainindexes_to_open: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("open"),
compressed,
StorableVecGeneatorOptions::default().add_first(),
)?,
chainindexes_to_high: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("high"),
compressed,
StorableVecGeneatorOptions::default().add_max(),
)?,
chainindexes_to_low: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("low"),
compressed,
StorableVecGeneatorOptions::default().add_min(),
)?,
chainindexes_to_close: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("close"),
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
chainindexes_to_sats_per_dollar: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("sats_per_dollar"),
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
weekindex_to_ohlc: StorableVec::forced_import(
&path.join("weekindex_to_ohlc"),
Version::from(1),
compressed,
)?,
difficultyepoch_to_ohlc: StorableVec::forced_import(
&path.join("difficultyepoch_to_ohlc"),
Version::from(1),
compressed,
)?,
monthindex_to_ohlc: StorableVec::forced_import(
&path.join("monthindex_to_ohlc"),
Version::from(1),
compressed,
)?,
yearindex_to_ohlc: StorableVec::forced_import(
&path.join("yearindex_to_ohlc"),
Version::from(1),
compressed,
)?,
// halvingepoch_to_ohlc: StorableVec::forced_import(&path.join("halvingepoch_to_ohlc"), Version::from(1), compressed)?,
decadeindex_to_ohlc: StorableVec::forced_import(
&path.join("decadeindex_to_ohlc"),
Version::from(1),
compressed,
)?,
})
}
@@ -331,33 +429,340 @@ impl Vecs {
exit,
)?;
self.timeindexes_to_close.compute(
&mut self.dateindex_to_close,
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_high.compute(
&mut self.dateindex_to_high,
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_low.compute(
&mut self.dateindex_to_low,
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_open.compute(
&mut self.dateindex_to_open,
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_close.compute(
&mut self.height_to_close,
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_high.compute(
&mut self.height_to_high,
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_low.compute(
&mut self.height_to_low,
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_open.compute(
&mut self.height_to_open,
indexes,
starting_indexes,
exit,
)?;
self.weekindex_to_ohlc.compute_transform(
starting_indexes.weekindex,
self.timeindexes_to_close
.weekindex
.last
.as_mut()
.unwrap()
.mut_vec(),
|(i, close, ..)| {
(
i,
OHLCDollars {
open: *self
.timeindexes_to_open
.weekindex
.first
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
high: *self
.timeindexes_to_high
.weekindex
.max
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
low: *self
.timeindexes_to_low
.weekindex
.min
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
close,
},
)
},
exit,
)?;
self.difficultyepoch_to_ohlc.compute_transform(
starting_indexes.difficultyepoch,
self.chainindexes_to_close
.difficultyepoch
.last
.as_mut()
.unwrap()
.mut_vec(),
|(i, close, ..)| {
(
i,
OHLCDollars {
open: *self
.chainindexes_to_open
.difficultyepoch
.first
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
high: *self
.chainindexes_to_high
.difficultyepoch
.max
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
low: *self
.chainindexes_to_low
.difficultyepoch
.min
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
close,
},
)
},
exit,
)?;
self.monthindex_to_ohlc.compute_transform(
starting_indexes.monthindex,
self.timeindexes_to_close
.monthindex
.last
.as_mut()
.unwrap()
.mut_vec(),
|(i, close, ..)| {
(
i,
OHLCDollars {
open: *self
.timeindexes_to_open
.monthindex
.first
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
high: *self
.timeindexes_to_high
.monthindex
.max
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
low: *self
.timeindexes_to_low
.monthindex
.min
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
close,
},
)
},
exit,
)?;
self.yearindex_to_ohlc.compute_transform(
starting_indexes.yearindex,
self.timeindexes_to_close
.yearindex
.last
.as_mut()
.unwrap()
.mut_vec(),
|(i, close, ..)| {
(
i,
OHLCDollars {
open: *self
.timeindexes_to_open
.yearindex
.first
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
high: *self
.timeindexes_to_high
.yearindex
.max
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
low: *self
.timeindexes_to_low
.yearindex
.min
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
close,
},
)
},
exit,
)?;
// self.halvingepoch_to_ohlc
// .compute_transform(starting_indexes.halvingepoch, other, t, exit)?;
self.decadeindex_to_ohlc.compute_transform(
starting_indexes.decadeindex,
self.timeindexes_to_close
.decadeindex
.last
.as_mut()
.as_mut()
.unwrap()
.mut_vec(),
|(i, close, ..)| {
(
i,
OHLCDollars {
open: *self
.timeindexes_to_open
.decadeindex
.first
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
high: *self
.timeindexes_to_high
.decadeindex
.max
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
low: *self
.timeindexes_to_low
.decadeindex
.min
.as_mut()
.unwrap()
.get(i)
.unwrap()
.unwrap(),
close,
},
)
},
exit,
)?;
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
vec![
self.dateindex_to_close.any_vec(),
self.dateindex_to_close_in_cents.any_vec(),
self.dateindex_to_high.any_vec(),
self.dateindex_to_high_in_cents.any_vec(),
self.dateindex_to_low.any_vec(),
self.dateindex_to_low_in_cents.any_vec(),
self.dateindex_to_ohlc.any_vec(),
self.dateindex_to_ohlc_in_cents.any_vec(),
self.dateindex_to_open.any_vec(),
self.dateindex_to_open_in_cents.any_vec(),
self.dateindex_to_sats_per_dollar.any_vec(),
self.height_to_close.any_vec(),
self.height_to_close_in_cents.any_vec(),
self.height_to_high.any_vec(),
self.height_to_high_in_cents.any_vec(),
self.height_to_low.any_vec(),
self.height_to_low_in_cents.any_vec(),
self.height_to_ohlc.any_vec(),
self.height_to_ohlc_in_cents.any_vec(),
self.height_to_open.any_vec(),
self.height_to_open_in_cents.any_vec(),
self.height_to_sats_per_dollar.any_vec(),
vec![
self.dateindex_to_close.any_vec(),
self.dateindex_to_close_in_cents.any_vec(),
self.dateindex_to_high.any_vec(),
self.dateindex_to_high_in_cents.any_vec(),
self.dateindex_to_low.any_vec(),
self.dateindex_to_low_in_cents.any_vec(),
self.dateindex_to_ohlc.any_vec(),
self.dateindex_to_ohlc_in_cents.any_vec(),
self.dateindex_to_open.any_vec(),
self.dateindex_to_open_in_cents.any_vec(),
self.dateindex_to_sats_per_dollar.any_vec(),
self.height_to_close.any_vec(),
self.height_to_close_in_cents.any_vec(),
self.height_to_high.any_vec(),
self.height_to_high_in_cents.any_vec(),
self.height_to_low.any_vec(),
self.height_to_low_in_cents.any_vec(),
self.height_to_ohlc.any_vec(),
self.height_to_ohlc_in_cents.any_vec(),
self.height_to_open.any_vec(),
self.height_to_open_in_cents.any_vec(),
self.height_to_sats_per_dollar.any_vec(),
self.weekindex_to_ohlc.any_vec(),
self.difficultyepoch_to_ohlc.any_vec(),
self.monthindex_to_ohlc.any_vec(),
self.yearindex_to_ohlc.any_vec(),
// self.halvingepoch_to_ohlc.any_vec(),
self.decadeindex_to_ohlc.any_vec(),
],
self.timeindexes_to_close.as_any_vecs(),
self.timeindexes_to_high.as_any_vecs(),
self.timeindexes_to_low.as_any_vecs(),
self.timeindexes_to_open.as_any_vecs(),
self.chainindexes_to_close.as_any_vecs(),
self.chainindexes_to_high.as_any_vecs(),
self.chainindexes_to_low.as_any_vecs(),
self.chainindexes_to_open.as_any_vecs(),
]
.concat()
}
}

View File

@@ -0,0 +1,93 @@
use std::path::Path;
use brk_core::{Dateindex, Decadeindex, Monthindex, Weekindex, Yearindex};
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed};
use crate::storage::vecs::{Indexes, base::StorableVec, indexes};
use super::{ComputedType, StorableVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct StorableVecsStatsFromDate<T>
where
T: ComputedType + PartialOrd,
{
pub weekindex: StorableVecBuilder<Weekindex, T>,
pub monthindex: StorableVecBuilder<Monthindex, T>,
pub yearindex: StorableVecBuilder<Yearindex, T>,
pub decadeindex: StorableVecBuilder<Decadeindex, T>,
}
impl<T> StorableVecsStatsFromDate<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let options = options.remove_percentiles();
Ok(Self {
weekindex: StorableVecBuilder::forced_import(path, compressed, options)?,
monthindex: StorableVecBuilder::forced_import(path, compressed, options)?,
yearindex: StorableVecBuilder::forced_import(path, compressed, options)?,
decadeindex: StorableVecBuilder::forced_import(path, compressed, options)?,
})
}
pub fn compute(
&mut self,
source: &mut StorableVec<Dateindex, T>,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
self.weekindex.compute(
starting_indexes.weekindex,
source,
indexes.weekindex_to_first_dateindex.mut_vec(),
indexes.weekindex_to_last_dateindex.mut_vec(),
exit,
)?;
self.monthindex.compute(
starting_indexes.monthindex,
source,
indexes.monthindex_to_first_dateindex.mut_vec(),
indexes.monthindex_to_last_dateindex.mut_vec(),
exit,
)?;
self.yearindex.from_aligned(
starting_indexes.yearindex,
&mut self.monthindex,
indexes.yearindex_to_first_monthindex.mut_vec(),
indexes.yearindex_to_last_monthindex.mut_vec(),
exit,
)?;
self.decadeindex.from_aligned(
starting_indexes.decadeindex,
&mut self.yearindex,
indexes.decadeindex_to_first_yearindex.mut_vec(),
indexes.decadeindex_to_last_yearindex.mut_vec(),
exit,
)?;
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
self.weekindex.as_any_vecs(),
self.monthindex.as_any_vecs(),
self.yearindex.as_any_vecs(),
self.decadeindex.as_any_vecs(),
]
.concat()
}
}

View File

@@ -9,9 +9,9 @@ use crate::storage::vecs::{Indexes, base::StorableVec, indexes};
use super::{ComputedType, StorableVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct StorableVecGeneatorByIndex<T>
pub struct StorableVecsStatsFromHeight<T>
where
T: ComputedType + Ord,
T: ComputedType + PartialOrd,
{
pub dateindex: StorableVecBuilder<Dateindex, T>,
pub weekindex: StorableVecBuilder<Weekindex, T>,
@@ -22,7 +22,7 @@ where
pub decadeindex: StorableVecBuilder<Decadeindex, T>,
}
impl<T> StorableVecGeneatorByIndex<T>
impl<T> StorableVecsStatsFromHeight<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,

View File

@@ -0,0 +1,63 @@
use std::path::Path;
use brk_core::{Difficultyepoch, Height};
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed};
use crate::storage::vecs::{Indexes, base::StorableVec, indexes};
use super::{ComputedType, StorableVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct StorableVecsStatsFromHeightStrict<T>
where
T: ComputedType + PartialOrd,
{
pub difficultyepoch: StorableVecBuilder<Difficultyepoch, T>,
// pub halvingepoch: StorableVecGeneator<Halvingepoch, T>, // TODO
}
impl<T> StorableVecsStatsFromHeightStrict<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let options = options.remove_percentiles();
Ok(Self {
difficultyepoch: StorableVecBuilder::forced_import(path, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, compressed, options)?,
})
}
pub fn compute(
&mut self,
source: &mut StorableVec<Height, T>,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
self.difficultyepoch.compute(
starting_indexes.difficultyepoch,
source,
indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(),
exit,
)?;
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
self.difficultyepoch.as_any_vecs(),
// self.halvingepoch.as_any_vecs(),
]
.concat()
}
}

View File

@@ -13,17 +13,17 @@ where
I: StoredIndex,
T: ComputedType,
{
first: Option<StorableVec<I, T>>,
average: Option<StorableVec<I, T>>,
sum: Option<StorableVec<I, T>>,
max: Option<StorableVec<I, T>>,
_90p: Option<StorableVec<I, T>>,
_75p: Option<StorableVec<I, T>>,
median: Option<StorableVec<I, T>>,
_25p: Option<StorableVec<I, T>>,
_10p: Option<StorableVec<I, T>>,
min: Option<StorableVec<I, T>>,
last: Option<StorableVec<I, T>>,
pub first: Option<StorableVec<I, T>>,
pub average: Option<StorableVec<I, T>>,
pub sum: Option<StorableVec<I, T>>,
pub max: Option<StorableVec<I, T>>,
pub _90p: Option<StorableVec<I, T>>,
pub _75p: Option<StorableVec<I, T>>,
pub median: Option<StorableVec<I, T>>,
pub _25p: Option<StorableVec<I, T>>,
pub _10p: Option<StorableVec<I, T>>,
pub min: Option<StorableVec<I, T>>,
pub last: Option<StorableVec<I, T>>,
}
impl<I, T> StorableVecBuilder<I, T>
@@ -226,7 +226,7 @@ where
.first
.as_mut()
.unwrap()
.get(last_index)
.get(first_index)
.unwrap()
.cloned()
.unwrap();
@@ -287,6 +287,8 @@ where
.into_iter()
.map(|v| f64::from(v))
.fold(0.0, |a, b| a + b);
// TODO: Multiply by count then divide by total
// Right now it's not 100% accurate as there could be more or less elements in the lower timeframe (28 days vs 31 days in a month for example)
let avg = T::from(total / len);
average.forced_push_at(i, avg, exit)?;
}

View File

@@ -1,7 +1,11 @@
mod from_date;
mod from_height;
mod from_height_strict;
mod generic;
mod grouped;
mod stored_type;
pub use from_date::*;
pub use from_height::*;
pub use from_height_strict::*;
pub use generic::*;
pub use grouped::*;
pub use stored_type::*;