computer + kibo: part 14 - fixes

This commit is contained in:
nym21
2025-04-19 11:45:26 +02:00
parent b1dcad86b4
commit d78c39fd8c
13 changed files with 121 additions and 88 deletions

View File

@@ -209,8 +209,6 @@ where
) -> Result<()>
where
I2: StoredIndex + StoredType,
T: Ord + From<f64>,
f64: From<T>,
{
let index = self.starting_index(max_from);
@@ -295,20 +293,14 @@ where
if needs_average_sum_or_total {
let len = values.len();
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(average) = self.average.as_mut() {
let len = len as f64;
let total = values
.iter()
.map(|v| f64::from(v.clone()))
.fold(0.0, |a, b| a + b);
let avg = T::from(total / len);
let avg = sum.clone() / len;
average.forced_push_at(i, avg, exit)?;
}
if needs_sum_or_total {
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
@@ -345,8 +337,6 @@ where
) -> Result<()>
where
I2: StoredIndex + StoredType,
T: Ord + From<f64>,
f64: From<T>,
{
if self._90p.is_some()
|| self._75p.is_some()
@@ -415,14 +405,12 @@ where
.as_ref()
.unwrap()
.collect_inclusive_range(first_index, last_index)?;
let len = values.len() as f64;
let total = values
.into_iter()
.map(|v| f64::from(v))
.fold(0.0, |a, b| a + b);
let len = values.len();
let total = values.into_iter().fold(T::from(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);
let avg = total / len;
average.forced_push_at(i, avg, exit)?;
}
@@ -432,6 +420,7 @@ where
.as_ref()
.unwrap()
.collect_inclusive_range(first_index, last_index)?;
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(sum_vec) = self.sum.as_mut() {

View File

@@ -27,8 +27,7 @@ const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromDateindex<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
T: ComputedType,
{
pub fn forced_import(
path: &Path,

View File

@@ -4,10 +4,10 @@ use brk_vec::StoredType;
pub trait ComputedType
where
Self: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self>,
Self: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + Ord,
{
}
impl<T> ComputedType for T where
T: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self>
T: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + Ord
{
}

View File

@@ -65,6 +65,9 @@ pub struct Vecs {
pub decadeindex_to_ohlc_in_sats: ComputedVec<Decadeindex, OHLCSats>,
}
const VERSION: Version = Version::ZERO;
const VERSION_IN_SATS: Version = Version::ONE;
impl Vecs {
pub fn forced_import(path: &Path, compressed: Compressed) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -87,7 +90,7 @@ impl Vecs {
)?,
dateindex_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("dateindex_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
dateindex_to_close_in_cents: ComputedVec::forced_import(
@@ -122,7 +125,7 @@ impl Vecs {
)?,
height_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("height_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
height_to_close_in_cents: ComputedVec::forced_import(
@@ -176,28 +179,28 @@ impl Vecs {
timeindexes_to_open_in_sats: ComputedVecsFromDateindex::forced_import(
path,
"open_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_first(),
)?,
timeindexes_to_high_in_sats: ComputedVecsFromDateindex::forced_import(
path,
"high_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_max(),
)?,
timeindexes_to_low_in_sats: ComputedVecsFromDateindex::forced_import(
path,
"low_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_min(),
)?,
timeindexes_to_close_in_sats: ComputedVecsFromDateindex::forced_import(
path,
"close_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
@@ -232,28 +235,28 @@ impl Vecs {
chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"open_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_first(),
)?,
chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"high_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_max(),
)?,
chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"low_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_min(),
)?,
chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"close_in_sats",
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
@@ -264,7 +267,7 @@ impl Vecs {
)?,
weekindex_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("weekindex_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
difficultyepoch_to_ohlc: ComputedVec::forced_import(
@@ -274,7 +277,7 @@ impl Vecs {
)?,
difficultyepoch_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("difficultyepoch_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
monthindex_to_ohlc: ComputedVec::forced_import(
@@ -284,7 +287,7 @@ impl Vecs {
)?,
monthindex_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("monthindex_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
quarterindex_to_ohlc: ComputedVec::forced_import(
@@ -294,7 +297,7 @@ impl Vecs {
)?,
quarterindex_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("quarterindex_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
yearindex_to_ohlc: ComputedVec::forced_import(
@@ -304,7 +307,7 @@ impl Vecs {
)?,
yearindex_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("yearindex_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
// halvingepoch_to_ohlc: StorableVec::forced_import(&path.join("halvingepoch_to_ohlc"), Version::ZERO, compressed)?,
@@ -315,7 +318,7 @@ impl Vecs {
)?,
decadeindex_to_ohlc_in_sats: ComputedVec::forced_import(
&path.join("decadeindex_to_ohlc_in_sats"),
Version::ZERO,
VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
)?,
})