diff --git a/Cargo.lock b/Cargo.lock index efe7a9111..38ff34c90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1150,21 +1150,11 @@ checksum = "6236364b88b9b6d0bc181ba374cf1ab55ba3ef97a1cb6f8cddad48a273767fb5" [[package]] name = "bzip2" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47" +checksum = "bea8dcd42434048e4f7a304411d9273a411f647446c1234a65ce0554923f4cff" dependencies = [ - "bzip2-sys", -] - -[[package]] -name = "bzip2-sys" -version = "0.1.13+1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14" -dependencies = [ - "cc", - "pkg-config", + "libbz2-rs-sys", ] [[package]] @@ -1237,18 +1227,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" +checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" +checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" dependencies = [ "anstream", "anstyle", @@ -1258,9 +1248,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" dependencies = [ "heck", "proc-macro2", @@ -1912,11 +1902,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", - "js-sys", "libc", "r-efi", "wasi 0.14.2+wasi-0.2.4", - "wasm-bindgen", ] [[package]] @@ -2316,6 +2304,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "libbz2-rs-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775bf80d5878ab7c2b1080b5351a48b2f737d9f6f8b383574eebcc22be0dfccb" + [[package]] name = "libc" version = "0.2.174" @@ -3318,6 +3312,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppmd-rust" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c834641d8ad1b348c9ee86dec3b9840d805acd5f24daa5f90c788951a52ff59b" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -4996,9 +4996,9 @@ dependencies = [ [[package]] name = "zip" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ab361742de920c5535880f89bbd611ee62002bf11341d16a5f057bb8ba6899" +checksum = "9aed4ac33e8eb078c89e6cbb1d5c4c7703ec6d299fc3e7c3695af8f8b423468b" dependencies = [ "aes", "arbitrary", @@ -5013,6 +5013,7 @@ dependencies = [ "liblzma", "memchr", "pbkdf2", + "ppmd-rust", "sha1", "time", "zeroize", diff --git a/Cargo.toml b/Cargo.toml index 64190ccbd..8e2d061cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,8 +43,8 @@ brk_server = { version = "0.0.76", path = "crates/brk_server" } brk_store = { version = "0.0.76", path = "crates/brk_store" } brk_vec = { version = "0.0.76", path = "crates/brk_vec" } byteview = "=0.6.1" -clap = { version = "4.5.40", features = ["string"] } -clap_derive = "4.5.40" +clap = { version = "4.5.41", features = ["string"] } +clap_derive = "4.5.41" color-eyre = "0.6.5" derive_deref = "1.1.1" fjall = "2.11.1" diff --git a/TODO.md b/TODO.md index 7946b35b8..1bf18338f 100644 --- a/TODO.md +++ b/TODO.md @@ -17,14 +17,19 @@ - add address counts relative to all datasets - make decade, quarter, year datasets `computed` instead of `eager` - add 6 months (semester) interval datasets to builder + - some datasets in `indexes` can probably be removed - add revived/sent supply datasets - add `in-sats` version of all price datasets (average and co) - add `p2pk` group (sum of `p2pk33` and `p2pk65`) + - add chopiness datasets + - add utxo count, address count, supply data for by reused addresses in groups by address type - add more date ranges (3-6 months and more) - add puell multiple dataset - add pi cycle dataset - - add ema of price + - add emas of price - add 7d and 30d ema to sell side risk ratio and sopr + - don't compute everything for all cohorts as some datasets combinations are irrelevant + - addresses/utxos by amount don't need mvrvz for example - add all possible charts from: - https://mainnet.observer - https://glassnode.com @@ -73,6 +78,7 @@ - remove `sum` series when it's a duplicate of the `base` (in subsidy for example) - selected unit sometimes changes when going back end forth - add support for custom charts + - separate z-score charts from "realized price" (with their own prices), have 4y, 2y and 1y - price scale format depends on unit, hide digits for sats for example (if/when possible) - table - pagination diff --git a/crates/brk_computer/src/vecs/blocks.rs b/crates/brk_computer/src/vecs/blocks.rs index 75644192d..1abde0813 100644 --- a/crates/brk_computer/src/vecs/blocks.rs +++ b/crates/brk_computer/src/vecs/blocks.rs @@ -8,9 +8,11 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format}; +use crate::vecs::grouped::Source; + use super::{ Indexes, - grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions}, + grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, EagerVecBuilderOptions}, indexes, }; @@ -34,7 +36,7 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, ) -> color_eyre::Result { Ok(Self { @@ -47,18 +49,20 @@ impl Vecs { timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import( path, "timestamp", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_first(), + computation, + EagerVecBuilderOptions::default().add_first(), )?, indexes_to_block_interval: ComputedVecsFromHeight::forced_import( path, "block_interval", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_percentiles() .add_minmax() .add_average(), @@ -66,32 +70,29 @@ impl Vecs { indexes_to_block_count: ComputedVecsFromHeight::forced_import( path, "block_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_block_weight: ComputedVecsFromHeight::forced_import( path, "block_weight", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_block_size: ComputedVecsFromHeight::forced_import( path, "block_size", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, height_to_vbytes: EagerVec::forced_import( path, @@ -102,12 +103,11 @@ impl Vecs { indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import( path, "block_vbytes", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, difficultyepoch_to_timestamp: EagerVec::forced_import( path, diff --git a/crates/brk_computer/src/vecs/cointime.rs b/crates/brk_computer/src/vecs/cointime.rs index a6c49cd2a..bf0bdd173 100644 --- a/crates/brk_computer/src/vecs/cointime.rs +++ b/crates/brk_computer/src/vecs/cointime.rs @@ -7,13 +7,13 @@ use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator}; use crate::vecs::{ fetched, - grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight}, + grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, Source}, stateful, transactions, }; use super::{ Indexes, - grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, + grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions}, indexes, }; @@ -51,7 +51,7 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, fetched: Option<&fetched::Vecs>, ) -> color_eyre::Result { @@ -61,194 +61,207 @@ impl Vecs { indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import( path, "coinblocks_created", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_coinblocks_stored: ComputedVecsFromHeight::forced_import( path, "coinblocks_stored", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_liveliness: ComputedVecsFromHeight::forced_import( path, "liveliness", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_vaultedness: ComputedVecsFromHeight::forced_import( path, "vaultedness", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight::forced_import( path, "activity_to_vaultedness_ratio", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_vaulted_supply: ComputedValueVecsFromHeight::forced_import( path, "vaulted_supply", - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, )?, indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import( path, "active_supply", - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, )?, indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import( path, "thermo_cap", - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_investor_cap: ComputedVecsFromHeight::forced_import( path, "investor_cap", - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_vaulted_cap: ComputedVecsFromHeight::forced_import( path, "vaulted_cap", - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_active_cap: ComputedVecsFromHeight::forced_import( path, "active_cap", - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_vaulted_price: ComputedVecsFromHeight::forced_import( path, "vaulted_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import( path, "vaulted_price", - false, + Source::None, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_active_price: ComputedVecsFromHeight::forced_import( path, "active_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import( path, "active_price", - false, + Source::None, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_true_market_mean: ComputedVecsFromHeight::forced_import( path, "true_market_mean", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_true_market_mean_ratio: ComputedRatioVecsFromDateIndex::forced_import( path, "true_market_mean", - false, + Source::None, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_cointime_value_destroyed: ComputedVecsFromHeight::forced_import( path, "cointime_value_destroyed", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_cointime_value_created: ComputedVecsFromHeight::forced_import( path, "cointime_value_created", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_cointime_value_stored: ComputedVecsFromHeight::forced_import( path, "cointime_value_stored", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_cointime_price: ComputedVecsFromHeight::forced_import( path, "cointime_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_cointime_cap: ComputedVecsFromHeight::forced_import( path, "cointime_cap", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import( path, "cointime_price", - false, + Source::None, version + VERSION + Version::ZERO, format, + computation, )?, }) } diff --git a/crates/brk_computer/src/vecs/constants.rs b/crates/brk_computer/src/vecs/constants.rs index 2180f727d..1a76cc36c 100644 --- a/crates/brk_computer/src/vecs/constants.rs +++ b/crates/brk_computer/src/vecs/constants.rs @@ -5,9 +5,11 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, AnyVec, Computation, Format}; +use crate::vecs::grouped::Source; + use super::{ Indexes, - grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, + grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions}, indexes, }; @@ -25,41 +27,45 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, ) -> color_eyre::Result { Ok(Self { constant_0: ComputedVecsFromHeight::forced_import( path, "constant_0", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, constant_1: ComputedVecsFromHeight::forced_import( path, "constant_1", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, constant_50: ComputedVecsFromHeight::forced_import( path, "constant_50", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, constant_100: ComputedVecsFromHeight::forced_import( path, "constant_100", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, }) } diff --git a/crates/brk_computer/src/vecs/fetched.rs b/crates/brk_computer/src/vecs/fetched.rs index 21c32eeb1..8a003053d 100644 --- a/crates/brk_computer/src/vecs/fetched.rs +++ b/crates/brk_computer/src/vecs/fetched.rs @@ -2,18 +2,19 @@ use std::path::Path; use brk_core::{ Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex, - OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, Version, WeekIndex, YearIndex, + OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, SemesterIndex, Version, WeekIndex, + YearIndex, }; use brk_exit::Exit; use brk_fetcher::Fetcher; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format, StoredIndex}; +use crate::vecs::grouped::Source; + use super::{ Indexes, - grouped::{ - ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, StorableVecGeneatorOptions, - }, + grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, EagerVecBuilderOptions}, indexes, }; @@ -57,6 +58,8 @@ pub struct Vecs { pub monthindex_to_ohlc_in_sats: EagerVec, pub quarterindex_to_ohlc: EagerVec, pub quarterindex_to_ohlc_in_sats: EagerVec, + pub semesterindex_to_ohlc: EagerVec, + pub semesterindex_to_ohlc_in_sats: EagerVec, pub yearindex_to_ohlc: EagerVec, pub yearindex_to_ohlc_in_sats: EagerVec, // pub halvingepoch_to_ohlc: StorableVec, @@ -72,7 +75,7 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, ) -> color_eyre::Result { let mut fetched_path = path.to_owned(); @@ -167,122 +170,130 @@ impl Vecs { timeindexes_to_open: ComputedVecsFromDateIndex::forced_import( path, "open", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_first(), + computation, + EagerVecBuilderOptions::default().add_first(), )?, timeindexes_to_high: ComputedVecsFromDateIndex::forced_import( path, "high", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_max(), + computation, + EagerVecBuilderOptions::default().add_max(), )?, timeindexes_to_low: ComputedVecsFromDateIndex::forced_import( path, "low", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_min(), + computation, + EagerVecBuilderOptions::default().add_min(), )?, timeindexes_to_close: ComputedVecsFromDateIndex::forced_import( path, "close", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import( path, "open_in_sats", - true, + Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_first(), + computation, + EagerVecBuilderOptions::default().add_first(), )?, timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import( path, "high_in_sats", - true, + Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_max(), + computation, + EagerVecBuilderOptions::default().add_max(), )?, timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import( path, "low_in_sats", - true, + Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_min(), + computation, + EagerVecBuilderOptions::default().add_min(), )?, timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import( path, "close_in_sats", - true, + Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import( path, "open", version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_first(), + EagerVecBuilderOptions::default().add_first(), )?, chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import( path, "high", version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_max(), + EagerVecBuilderOptions::default().add_max(), )?, chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import( path, "low", version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_min(), + EagerVecBuilderOptions::default().add_min(), )?, chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import( path, "close", version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + EagerVecBuilderOptions::default().add_last(), )?, chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import( path, "open_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_first(), + EagerVecBuilderOptions::default().add_first(), )?, chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import( path, "high_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_max(), + EagerVecBuilderOptions::default().add_max(), )?, chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import( path, "low_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_min(), + EagerVecBuilderOptions::default().add_min(), )?, chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import( path, "close_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + EagerVecBuilderOptions::default().add_last(), )?, weekindex_to_ohlc: EagerVec::forced_import( path, @@ -332,6 +343,18 @@ impl Vecs { version + VERSION + VERSION_IN_SATS + Version::ZERO, format, )?, + semesterindex_to_ohlc: EagerVec::forced_import( + path, + "ohlc", + version + VERSION + Version::ZERO, + format, + )?, + semesterindex_to_ohlc_in_sats: EagerVec::forced_import( + path, + "ohlc_in_sats", + version + VERSION + VERSION_IN_SATS + Version::ZERO, + format, + )?, yearindex_to_ohlc: EagerVec::forced_import( path, "ohlc", @@ -693,6 +716,27 @@ impl Vecs { exit, )?; + let mut semesterindex_first_iter = + self.timeindexes_to_open.semesterindex.unwrap_first().iter(); + let mut semesterindex_max_iter = self.timeindexes_to_high.semesterindex.unwrap_max().iter(); + let mut semesterindex_min_iter = self.timeindexes_to_low.semesterindex.unwrap_min().iter(); + self.semesterindex_to_ohlc.compute_transform( + starting_indexes.semesterindex, + self.timeindexes_to_close.semesterindex.unwrap_last(), + |(i, close, ..)| { + ( + i, + OHLCDollars { + open: semesterindex_first_iter.unwrap_get_inner(i), + high: semesterindex_max_iter.unwrap_get_inner(i), + low: semesterindex_min_iter.unwrap_get_inner(i), + close, + }, + ) + }, + exit, + )?; + let mut yearindex_first_iter = self.timeindexes_to_open.yearindex.unwrap_first().iter(); let mut yearindex_max_iter = self.timeindexes_to_high.yearindex.unwrap_max().iter(); let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter(); @@ -1044,6 +1088,40 @@ impl Vecs { exit, )?; + let mut semesterindex_first_iter = self + .timeindexes_to_open_in_sats + .semesterindex + .unwrap_first() + .iter(); + let mut semesterindex_max_iter = self + .timeindexes_to_high_in_sats + .semesterindex + .unwrap_max() + .iter(); + let mut semesterindex_min_iter = self + .timeindexes_to_low_in_sats + .semesterindex + .unwrap_min() + .iter(); + self.semesterindex_to_ohlc_in_sats.compute_transform( + starting_indexes.semesterindex, + self.timeindexes_to_close_in_sats + .semesterindex + .unwrap_last(), + |(i, close, ..)| { + ( + i, + OHLCSats { + open: semesterindex_first_iter.unwrap_get_inner(i), + high: semesterindex_max_iter.unwrap_get_inner(i), + low: semesterindex_min_iter.unwrap_get_inner(i), + close, + }, + ) + }, + exit, + )?; + let mut yearindex_first_iter = self .timeindexes_to_open_in_sats .yearindex @@ -1133,6 +1211,7 @@ impl Vecs { &self.difficultyepoch_to_ohlc, &self.monthindex_to_ohlc, &self.quarterindex_to_ohlc, + &self.semesterindex_to_ohlc, &self.yearindex_to_ohlc, // &self.halvingepoch_to_ohlc, &self.decadeindex_to_ohlc, @@ -1142,6 +1221,7 @@ impl Vecs { &self.difficultyepoch_to_ohlc_in_sats, &self.monthindex_to_ohlc_in_sats, &self.quarterindex_to_ohlc_in_sats, + &self.semesterindex_to_ohlc_in_sats, &self.yearindex_to_ohlc_in_sats, // &self.halvingepoch_to_ohlc_in_sats, &self.decadeindex_to_ohlc_in_sats, diff --git a/crates/brk_computer/src/vecs/grouped/builder_computed.rs b/crates/brk_computer/src/vecs/grouped/builder_computed.rs new file mode 100644 index 000000000..a3cf94f51 --- /dev/null +++ b/crates/brk_computer/src/vecs/grouped/builder_computed.rs @@ -0,0 +1,442 @@ +use std::path::Path; + +use brk_core::{FromCoarserIndex, Result, Version}; +use brk_exit::Exit; +use brk_vec::{ + AnyCollectableVec, AnyIterableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, Computation, + ComputedVec, ComputedVecFrom1, Format, StoredIndex, +}; + +use crate::vecs::grouped::{EagerVecBuilder, EagerVecBuilderOptions}; + +use super::ComputedType; + +#[derive(Clone)] +pub struct ComputedVecBuilder +where + I: StoredIndex, + T: ComputedType, +{ + pub first: Option>>, + pub average: Option>>, + pub sum: Option>>, + pub max: Option>>, + pub min: Option>>, + pub last: Option>>, + pub cumulative: Option>>, +} + +const VERSION: Version = Version::ZERO; + +impl ComputedVecBuilder +where + I: StoredIndex, + T: ComputedType + 'static, + S1I: StoredIndex + 'static + FromCoarserIndex, +{ + #[allow(clippy::too_many_arguments)] + pub fn forced_import( + path: &Path, + name: &str, + version: Version, + format: Format, + computation: Computation, + source: Option>, + source_extra: &EagerVecBuilder, + options: ComputedVecBuilderOptions, + ) -> color_eyre::Result { + let only_one_active = options.is_only_one_active(); + + let suffix = |s: &str| format!("{name}_{s}"); + + let maybe_suffix = |s: &str| { + if only_one_active { + name.to_string() + } else { + suffix(s) + } + }; + + Ok(Self { + first: options.first.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + &maybe_suffix("first"), + version + VERSION + Version::ZERO, + format, + source_extra + .first + .as_ref() + .map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()), + |i, source| { + source + .next_at(S1I::min_from(i)) + .map(|(_, cow)| cow.into_owned()) + }, + ) + .unwrap(), + ) + }), + last: options.last.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + name, + version + VERSION + Version::ZERO, + format, + source_extra.last.as_ref().map_or_else( + || { + source + .as_ref() + .unwrap_or_else(|| { + dbg!(path, name, I::to_string()); + panic!() + }) + .clone() + }, + |v| v.clone(), + ), + |i, source| { + source + .next_at(S1I::max_from(i)) + .map(|(_, cow)| cow.into_owned()) + }, + ) + .unwrap(), + ) + }), + min: options.min.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + &maybe_suffix("min"), + version + VERSION + Version::ZERO, + format, + source_extra + .min + .as_ref() + .map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()), + |i, source| { + S1I::inclusive_range_from(i) + .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .min() + }, + ) + .unwrap(), + ) + }), + max: options.max.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + &maybe_suffix("max"), + version + VERSION + Version::ZERO, + format, + source_extra + .max + .as_ref() + .map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()), + |i, source| { + S1I::inclusive_range_from(i) + .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .max() + }, + ) + .unwrap(), + ) + }), + average: options.average.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + &maybe_suffix("average"), + version + VERSION + Version::ZERO, + format, + source_extra + .average + .as_ref() + .map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()), + |i, source| { + let vec = S1I::inclusive_range_from(i) + .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .collect::>(); + if vec.is_empty() { + return None; + } + let mut sum = T::from(0); + let len = vec.len(); + vec.into_iter().for_each(|v| sum += v); + Some(sum / len) + }, + ) + .unwrap(), + ) + }), + sum: options.sum.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + &(if !options.last && !options.average && !options.min && !options.max { + name.to_string() + } else { + maybe_suffix("sum") + }), + version + VERSION + Version::ZERO, + format, + source_extra + .sum + .as_ref() + .map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()), + |i, source| { + let vec = S1I::inclusive_range_from(i) + .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .collect::>(); + if vec.is_empty() { + return None; + } + let mut sum = T::from(0); + vec.into_iter().for_each(|v| sum += v); + Some(sum) + }, + ) + .unwrap(), + ) + }), + cumulative: options.cumulative.then(|| { + Box::new( + ComputedVec::forced_import_or_init_from_1( + computation, + path, + &suffix("cumulative"), + version + VERSION + Version::ZERO, + format, + source_extra.cumulative.as_ref().unwrap().boxed_clone(), + |i, source| { + source + .next_at(S1I::max_from(i)) + .map(|(_, cow)| cow.into_owned()) + }, + ) + .unwrap(), + ) + }), + }) + } + + pub fn compute_if_necessary( + &mut self, + max_from: I, + len_source: &impl AnyIterableVec, + exit: &Exit, + ) -> Result<()> { + if let Some(first) = self.first.as_mut() { + first.compute_if_necessary(max_from, len_source, exit)?; + } + if let Some(last) = self.last.as_mut() { + last.compute_if_necessary(max_from, len_source, exit)?; + } + if let Some(min) = self.min.as_mut() { + min.compute_if_necessary(max_from, len_source, exit)?; + } + if let Some(max) = self.max.as_mut() { + max.compute_if_necessary(max_from, len_source, exit)?; + } + if let Some(average) = self.average.as_mut() { + average.compute_if_necessary(max_from, len_source, exit)?; + } + if let Some(sum) = self.sum.as_mut() { + sum.compute_if_necessary(max_from, len_source, exit)?; + } + if let Some(cumulative) = self.cumulative.as_mut() { + cumulative.compute_if_necessary(max_from, len_source, exit)?; + } + + Ok(()) + } + + pub fn starting_index(&self, max_from: I) -> I { + max_from.min(I::from( + self.vecs().into_iter().map(|v| v.len()).min().unwrap(), + )) + } + + pub fn unwrap_first(&self) -> &ComputedVecFrom1 { + self.first.as_ref().unwrap() + } + #[allow(unused)] + pub fn unwrap_average(&self) -> &ComputedVecFrom1 { + self.average.as_ref().unwrap() + } + pub fn unwrap_sum(&self) -> &ComputedVecFrom1 { + self.sum.as_ref().unwrap() + } + pub fn unwrap_max(&self) -> &ComputedVecFrom1 { + self.max.as_ref().unwrap() + } + pub fn unwrap_min(&self) -> &ComputedVecFrom1 { + self.min.as_ref().unwrap() + } + pub fn unwrap_last(&self) -> &ComputedVecFrom1 { + self.last.as_ref().unwrap() + } + #[allow(unused)] + pub fn unwrap_cumulative(&self) -> &ComputedVecFrom1 { + self.cumulative.as_ref().unwrap() + } + + pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { + let mut v: Vec<&dyn AnyCollectableVec> = vec![]; + + if let Some(first) = self.first.as_ref() { + v.push(first.as_ref()); + } + if let Some(last) = self.last.as_ref() { + v.push(last.as_ref()); + } + if let Some(min) = self.min.as_ref() { + v.push(min.as_ref()); + } + if let Some(max) = self.max.as_ref() { + v.push(max.as_ref()); + } + if let Some(average) = self.average.as_ref() { + v.push(average.as_ref()); + } + if let Some(sum) = self.sum.as_ref() { + v.push(sum.as_ref()); + } + if let Some(cumulative) = self.cumulative.as_ref() { + v.push(cumulative.as_ref()); + } + + v + } +} + +#[derive(Default, Clone, Copy)] +pub struct ComputedVecBuilderOptions { + average: bool, + sum: bool, + max: bool, + min: bool, + first: bool, + last: bool, + cumulative: bool, +} + +impl From for ComputedVecBuilderOptions { + fn from(value: EagerVecBuilderOptions) -> Self { + Self { + average: value.average(), + sum: value.sum(), + max: value.max(), + min: value.min(), + first: value.first(), + last: value.last(), + cumulative: value.cumulative(), + } + } +} + +impl ComputedVecBuilderOptions { + pub fn add_first(mut self) -> Self { + self.first = true; + self + } + + pub fn add_last(mut self) -> Self { + self.last = true; + self + } + + pub fn add_min(mut self) -> Self { + self.min = true; + self + } + + pub fn add_max(mut self) -> Self { + self.max = true; + self + } + + pub fn add_average(mut self) -> Self { + self.average = true; + self + } + + pub fn add_sum(mut self) -> Self { + self.sum = true; + self + } + + pub fn add_cumulative(mut self) -> Self { + self.cumulative = true; + self + } + + #[allow(unused)] + pub fn rm_min(mut self) -> Self { + self.min = false; + self + } + + #[allow(unused)] + pub fn rm_max(mut self) -> Self { + self.max = false; + self + } + + #[allow(unused)] + pub fn rm_average(mut self) -> Self { + self.average = false; + self + } + + #[allow(unused)] + pub fn rm_sum(mut self) -> Self { + self.sum = false; + self + } + + #[allow(unused)] + pub fn rm_cumulative(mut self) -> Self { + self.cumulative = false; + self + } + + pub fn add_minmax(mut self) -> Self { + self.min = true; + self.max = true; + self + } + + pub fn is_only_one_active(&self) -> bool { + [ + self.average, + self.sum, + self.max, + self.min, + self.first, + self.last, + self.cumulative, + ] + .iter() + .filter(|b| **b) + .count() + == 1 + } + + pub fn copy_self_extra(&self) -> Self { + Self { + cumulative: self.cumulative, + ..Self::default() + } + } +} diff --git a/crates/brk_computer/src/vecs/grouped/builder.rs b/crates/brk_computer/src/vecs/grouped/builder_eager.rs similarity index 96% rename from crates/brk_computer/src/vecs/grouped/builder.rs rename to crates/brk_computer/src/vecs/grouped/builder_eager.rs index 0a510df57..7c21026e6 100644 --- a/crates/brk_computer/src/vecs/grouped/builder.rs +++ b/crates/brk_computer/src/vecs/grouped/builder_eager.rs @@ -10,7 +10,7 @@ use crate::utils::get_percentile; use super::ComputedType; #[derive(Clone, Debug)] -pub struct ComputedVecBuilder +pub struct EagerVecBuilder where I: StoredIndex, T: ComputedType, @@ -31,7 +31,7 @@ where const VERSION: Version = Version::ZERO; -impl ComputedVecBuilder +impl EagerVecBuilder where I: StoredIndex, T: ComputedType, @@ -41,7 +41,7 @@ where name: &str, version: Version, format: Format, - options: StorableVecGeneatorOptions, + options: EagerVecBuilderOptions, ) -> color_eyre::Result { let only_one_active = options.is_only_one_active(); @@ -384,7 +384,7 @@ where pub fn from_aligned( &mut self, max_from: I, - source: &ComputedVecBuilder, + source: &EagerVecBuilder, first_indexes: &impl AnyIterableVec, count_indexes: &impl AnyIterableVec, exit: &Exit, @@ -706,7 +706,7 @@ where } #[derive(Default, Clone, Copy)] -pub struct StorableVecGeneatorOptions { +pub struct EagerVecBuilderOptions { average: bool, sum: bool, max: bool, @@ -721,7 +721,55 @@ pub struct StorableVecGeneatorOptions { cumulative: bool, } -impl StorableVecGeneatorOptions { +impl EagerVecBuilderOptions { + pub fn average(&self) -> bool { + self.average + } + + pub fn sum(&self) -> bool { + self.sum + } + + pub fn max(&self) -> bool { + self.max + } + + pub fn _90p(&self) -> bool { + self._90p + } + + pub fn _75p(&self) -> bool { + self._75p + } + + pub fn median(&self) -> bool { + self.median + } + + pub fn _25p(&self) -> bool { + self._25p + } + + pub fn _10p(&self) -> bool { + self._10p + } + + pub fn min(&self) -> bool { + self.min + } + + pub fn first(&self) -> bool { + self.first + } + + pub fn last(&self) -> bool { + self.last + } + + pub fn cumulative(&self) -> bool { + self.cumulative + } + pub fn add_first(mut self) -> Self { self.first = true; self diff --git a/crates/brk_computer/src/vecs/grouped/from_dateindex.rs b/crates/brk_computer/src/vecs/grouped/from_dateindex.rs index a99a1e066..4b2425b0b 100644 --- a/crates/brk_computer/src/vecs/grouped/from_dateindex.rs +++ b/crates/brk_computer/src/vecs/grouped/from_dateindex.rs @@ -1,15 +1,18 @@ use std::path::Path; use brk_core::{ - DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, Version, WeekIndex, YearIndex, + DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, SemesterIndex, Version, WeekIndex, + YearIndex, }; use brk_exit::Exit; use brk_indexer::Indexer; -use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format}; +use brk_vec::{ + AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Computation, EagerVec, Format, +}; -use crate::vecs::{Indexes, indexes}; +use crate::vecs::{Indexes, grouped::ComputedVecBuilder, indexes}; -use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions}; +use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions, Source}; #[derive(Clone)] pub struct ComputedVecsFromDateIndex @@ -17,33 +20,35 @@ where T: ComputedType + PartialOrd, { pub dateindex: Option>, - pub dateindex_extra: ComputedVecBuilder, - pub weekindex: ComputedVecBuilder, - pub monthindex: ComputedVecBuilder, - pub quarterindex: ComputedVecBuilder, - pub yearindex: ComputedVecBuilder, - pub decadeindex: ComputedVecBuilder, + pub dateindex_extra: EagerVecBuilder, + pub weekindex: ComputedVecBuilder, + pub monthindex: ComputedVecBuilder, + pub quarterindex: ComputedVecBuilder, + pub semesterindex: ComputedVecBuilder, + pub yearindex: ComputedVecBuilder, + pub decadeindex: ComputedVecBuilder, } const VERSION: Version = Version::ZERO; impl ComputedVecsFromDateIndex where - T: ComputedType, + T: ComputedType + 'static, { pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, - options: StorableVecGeneatorOptions, + computation: Computation, + options: EagerVecBuilderOptions, ) -> color_eyre::Result { - let dateindex = compute_source.then(|| { + let dateindex = source.is_compute().then(|| { EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap() }); - let dateindex_extra = ComputedVecBuilder::forced_import( + let dateindex_extra = EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -53,44 +58,71 @@ where let options = options.remove_percentiles(); + let dateindex_source = source.vec().or(dateindex.as_ref().map(|v| v.boxed_clone())); + Ok(Self { - dateindex, - dateindex_extra, weekindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + dateindex_source.clone(), + &dateindex_extra, + options.into(), )?, monthindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + dateindex_source.clone(), + &dateindex_extra, + options.into(), )?, quarterindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + dateindex_source.clone(), + &dateindex_extra, + options.into(), + )?, + semesterindex: ComputedVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + computation, + dateindex_source.clone(), + &dateindex_extra, + options.into(), )?, yearindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + dateindex_source.clone(), + &dateindex_extra, + options.into(), )?, decadeindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + dateindex_source.clone(), + &dateindex_extra, + options.into(), )?, + dateindex, + dateindex_extra, }) } @@ -133,65 +165,45 @@ where if let Some(dateindex) = dateindex { self.dateindex_extra .extend(starting_indexes.dateindex, dateindex, exit)?; - - self.weekindex.compute( - starting_indexes.weekindex, - dateindex, - &indexes.weekindex_to_first_dateindex, - &indexes.weekindex_to_dateindex_count, - exit, - )?; - - self.monthindex.compute( - starting_indexes.monthindex, - dateindex, - &indexes.monthindex_to_first_dateindex, - &indexes.monthindex_to_dateindex_count, - exit, - )?; } else { let dateindex = self.dateindex.as_ref().unwrap(); self.dateindex_extra .extend(starting_indexes.dateindex, dateindex, exit)?; - - self.weekindex.compute( - starting_indexes.weekindex, - dateindex, - &indexes.weekindex_to_first_dateindex, - &indexes.weekindex_to_dateindex_count, - exit, - )?; - - self.monthindex.compute( - starting_indexes.monthindex, - dateindex, - &indexes.monthindex_to_first_dateindex, - &indexes.monthindex_to_dateindex_count, - exit, - )?; } - self.quarterindex.from_aligned( + self.weekindex.compute_if_necessary( + starting_indexes.weekindex, + &indexes.weekindex_to_dateindex_count, + exit, + )?; + + self.monthindex.compute_if_necessary( + starting_indexes.monthindex, + &indexes.monthindex_to_dateindex_count, + exit, + )?; + + self.quarterindex.compute_if_necessary( starting_indexes.quarterindex, - &self.monthindex, - &indexes.quarterindex_to_first_monthindex, &indexes.quarterindex_to_monthindex_count, exit, )?; - self.yearindex.from_aligned( + self.semesterindex.compute_if_necessary( + starting_indexes.semesterindex, + &indexes.semesterindex_to_monthindex_count, + exit, + )?; + + self.yearindex.compute_if_necessary( starting_indexes.yearindex, - &self.monthindex, - &indexes.yearindex_to_first_monthindex, &indexes.yearindex_to_monthindex_count, exit, )?; - self.decadeindex.from_aligned( + self.decadeindex.compute_if_necessary( starting_indexes.decadeindex, - &self.yearindex, - &indexes.decadeindex_to_first_yearindex, &indexes.decadeindex_to_yearindex_count, exit, )?; @@ -208,6 +220,7 @@ where self.weekindex.vecs(), self.monthindex.vecs(), self.quarterindex.vecs(), + self.semesterindex.vecs(), self.yearindex.vecs(), self.decadeindex.vecs(), ] diff --git a/crates/brk_computer/src/vecs/grouped/from_height.rs b/crates/brk_computer/src/vecs/grouped/from_height.rs index 59218ee7d..09f3de5d0 100644 --- a/crates/brk_computer/src/vecs/grouped/from_height.rs +++ b/crates/brk_computer/src/vecs/grouped/from_height.rs @@ -1,16 +1,20 @@ use std::path::Path; use brk_core::{ - DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result, Version, - WeekIndex, YearIndex, + DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result, + SemesterIndex, Version, WeekIndex, YearIndex, }; use brk_exit::Exit; use brk_indexer::Indexer; -use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format}; +use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format}; -use crate::vecs::{Indexes, indexes}; +use crate::vecs::{ + Indexes, + grouped::{ComputedVecBuilder, Source}, + indexes, +}; -use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions}; +use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions}; #[derive(Clone)] pub struct ComputedVecsFromHeight @@ -18,38 +22,39 @@ where T: ComputedType + PartialOrd, { pub height: Option>, - pub height_extra: ComputedVecBuilder, - pub dateindex: ComputedVecBuilder, - pub weekindex: ComputedVecBuilder, - pub difficultyepoch: ComputedVecBuilder, - pub monthindex: ComputedVecBuilder, - pub quarterindex: ComputedVecBuilder, - // 6 months - pub yearindex: ComputedVecBuilder, + pub height_extra: EagerVecBuilder, + pub dateindex: EagerVecBuilder, + pub weekindex: ComputedVecBuilder, + pub difficultyepoch: EagerVecBuilder, + pub monthindex: ComputedVecBuilder, + pub quarterindex: ComputedVecBuilder, + pub semesterindex: ComputedVecBuilder, + pub yearindex: ComputedVecBuilder, // TODO: pub halvingepoch: StorableVecGeneator, - pub decadeindex: ComputedVecBuilder, + pub decadeindex: ComputedVecBuilder, } const VERSION: Version = Version::ZERO; impl ComputedVecsFromHeight where - T: ComputedType + Ord + From, + T: ComputedType + Ord + From + 'static, f64: From, { pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, - options: StorableVecGeneatorOptions, + computation: Computation, + options: EagerVecBuilderOptions, ) -> color_eyre::Result { - let height = compute_source.then(|| { + let height = source.is_compute().then(|| { EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap() }); - let height_extra = ComputedVecBuilder::forced_import( + let height_extra = EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -57,7 +62,7 @@ where options.copy_self_extra(), )?; - let dateindex = ComputedVecBuilder::forced_import( + let dateindex = EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -68,46 +73,71 @@ where let options = options.remove_percentiles(); Ok(Self { - height, - height_extra, - dateindex, weekindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, - )?, - difficultyepoch: ComputedVecBuilder::forced_import( - path, - name, - version + VERSION + Version::ZERO, - format, - options, + computation, + None, + &dateindex, + options.into(), )?, monthindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + None, + &dateindex, + options.into(), )?, quarterindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + None, + &dateindex, + options.into(), + )?, + semesterindex: ComputedVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + computation, + None, + &dateindex, + options.into(), )?, yearindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + None, + &dateindex, + options.into(), + )?, + decadeindex: ComputedVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + computation, + None, + &dateindex, + options.into(), )?, // halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?, - decadeindex: ComputedVecBuilder::forced_import( + height, + height_extra, + dateindex, + difficultyepoch: EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -189,42 +219,38 @@ where )?; } - self.weekindex.from_aligned( + self.weekindex.compute_if_necessary( starting_indexes.weekindex, - &self.dateindex, - &indexes.weekindex_to_first_dateindex, &indexes.weekindex_to_dateindex_count, exit, )?; - self.monthindex.from_aligned( + self.monthindex.compute_if_necessary( starting_indexes.monthindex, - &self.dateindex, - &indexes.monthindex_to_first_dateindex, &indexes.monthindex_to_dateindex_count, exit, )?; - self.quarterindex.from_aligned( + self.quarterindex.compute_if_necessary( starting_indexes.quarterindex, - &self.monthindex, - &indexes.quarterindex_to_first_monthindex, &indexes.quarterindex_to_monthindex_count, exit, )?; - self.yearindex.from_aligned( + self.semesterindex.compute_if_necessary( + starting_indexes.semesterindex, + &indexes.semesterindex_to_monthindex_count, + exit, + )?; + + self.yearindex.compute_if_necessary( starting_indexes.yearindex, - &self.monthindex, - &indexes.yearindex_to_first_monthindex, &indexes.yearindex_to_monthindex_count, exit, )?; - self.decadeindex.from_aligned( + self.decadeindex.compute_if_necessary( starting_indexes.decadeindex, - &self.yearindex, - &indexes.decadeindex_to_first_yearindex, &indexes.decadeindex_to_yearindex_count, exit, )?; @@ -243,6 +269,7 @@ where self.difficultyepoch.vecs(), self.monthindex.vecs(), self.quarterindex.vecs(), + self.semesterindex.vecs(), self.yearindex.vecs(), // self.halvingepoch.vecs(), self.decadeindex.vecs(), diff --git a/crates/brk_computer/src/vecs/grouped/from_height_strict.rs b/crates/brk_computer/src/vecs/grouped/from_height_strict.rs index 52b2226c7..ba319de3a 100644 --- a/crates/brk_computer/src/vecs/grouped/from_height_strict.rs +++ b/crates/brk_computer/src/vecs/grouped/from_height_strict.rs @@ -5,9 +5,9 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, EagerVec, Format}; -use crate::vecs::{indexes, Indexes}; +use crate::vecs::{Indexes, indexes}; -use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions}; +use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions}; #[derive(Clone)] pub struct ComputedVecsFromHeightStrict @@ -15,8 +15,8 @@ where T: ComputedType + PartialOrd, { pub height: EagerVec, - pub height_extra: ComputedVecBuilder, - pub difficultyepoch: ComputedVecBuilder, + pub height_extra: EagerVecBuilder, + pub difficultyepoch: EagerVecBuilder, // TODO: pub halvingepoch: StorableVecGeneator, } @@ -32,12 +32,12 @@ where name: &str, version: Version, format: Format, - options: StorableVecGeneatorOptions, + options: EagerVecBuilderOptions, ) -> color_eyre::Result { let height = EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)?; - let height_extra = ComputedVecBuilder::forced_import( + let height_extra = EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -50,7 +50,7 @@ where Ok(Self { height, height_extra, - difficultyepoch: ComputedVecBuilder::forced_import( + difficultyepoch: EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, diff --git a/crates/brk_computer/src/vecs/grouped/from_txindex.rs b/crates/brk_computer/src/vecs/grouped/from_txindex.rs index 031b95828..95762da37 100644 --- a/crates/brk_computer/src/vecs/grouped/from_txindex.rs +++ b/crates/brk_computer/src/vecs/grouped/from_txindex.rs @@ -2,17 +2,22 @@ use std::path::Path; use brk_core::{ Bitcoin, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, MonthIndex, QuarterIndex, - Result, Sats, TxIndex, Version, WeekIndex, YearIndex, + Result, Sats, SemesterIndex, TxIndex, Version, WeekIndex, YearIndex, }; use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{ - AnyCollectableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex, VecIterator, + AnyCollectableVec, AnyVec, CollectableVec, Computation, EagerVec, Format, StoredIndex, + VecIterator, }; -use crate::vecs::{Indexes, fetched, indexes}; +use crate::vecs::{ + Indexes, fetched, + grouped::{ComputedVecBuilder, Source}, + indexes, +}; -use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions}; +use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions}; #[derive(Clone)] pub struct ComputedVecsFromTxindex @@ -20,40 +25,42 @@ where T: ComputedType + PartialOrd, { pub txindex: Option>>, - pub height: ComputedVecBuilder, - pub dateindex: ComputedVecBuilder, - pub weekindex: ComputedVecBuilder, - pub difficultyepoch: ComputedVecBuilder, - pub monthindex: ComputedVecBuilder, - pub quarterindex: ComputedVecBuilder, - pub yearindex: ComputedVecBuilder, + pub height: EagerVecBuilder, + pub dateindex: EagerVecBuilder, + pub weekindex: ComputedVecBuilder, + pub difficultyepoch: EagerVecBuilder, + pub monthindex: ComputedVecBuilder, + pub quarterindex: ComputedVecBuilder, + pub semesterindex: ComputedVecBuilder, + pub yearindex: ComputedVecBuilder, // TODO: pub halvingepoch: StorableVecGeneator, - pub decadeindex: ComputedVecBuilder, + pub decadeindex: ComputedVecBuilder, } const VERSION: Version = Version::ZERO; impl ComputedVecsFromTxindex where - T: ComputedType + Ord + From, + T: ComputedType + Ord + From + 'static, f64: From, { pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, - options: StorableVecGeneatorOptions, + computation: Computation, + options: EagerVecBuilderOptions, ) -> color_eyre::Result { - let txindex = compute_source.then(|| { + let txindex = source.is_compute().then(|| { Box::new( EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format) .unwrap(), ) }); - let height = ComputedVecBuilder::forced_import( + let height = EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -63,45 +70,80 @@ where let options = options.remove_percentiles(); + let dateindex = EagerVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + options, + )?; + Ok(Self { - txindex, - height, - dateindex: ComputedVecBuilder::forced_import( - path, - name, - version + VERSION + Version::ZERO, - format, - options, - )?, weekindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, - )?, - difficultyepoch: ComputedVecBuilder::forced_import( - path, - name, - version + VERSION + Version::ZERO, - format, - options, + computation, + None, + &dateindex, + options.into(), )?, monthindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + None, + &dateindex, + options.into(), )?, quarterindex: ComputedVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, format, - options, + computation, + None, + &dateindex, + options.into(), + )?, + semesterindex: ComputedVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + computation, + None, + &dateindex, + options.into(), )?, yearindex: ComputedVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + computation, + None, + &dateindex, + options.into(), + )?, + decadeindex: ComputedVecBuilder::forced_import( + path, + name, + version + VERSION + Version::ZERO, + format, + computation, + None, + &dateindex, + options.into(), + )?, + + txindex, + height, + dateindex, + difficultyepoch: EagerVecBuilder::forced_import( path, name, version + VERSION + Version::ZERO, @@ -109,13 +151,6 @@ where options, )?, // halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?, - decadeindex: ComputedVecBuilder::forced_import( - path, - name, - version + VERSION + Version::ZERO, - format, - options, - )?, }) } @@ -196,42 +231,38 @@ where exit, )?; - self.weekindex.from_aligned( + self.weekindex.compute_if_necessary( starting_indexes.weekindex, - &self.dateindex, &indexes.weekindex_to_first_dateindex, - &indexes.weekindex_to_dateindex_count, exit, )?; - self.monthindex.from_aligned( + self.monthindex.compute_if_necessary( starting_indexes.monthindex, - &self.dateindex, - &indexes.monthindex_to_first_dateindex, &indexes.monthindex_to_dateindex_count, exit, )?; - self.quarterindex.from_aligned( + self.quarterindex.compute_if_necessary( starting_indexes.quarterindex, - &self.monthindex, - &indexes.quarterindex_to_first_monthindex, &indexes.quarterindex_to_monthindex_count, exit, )?; - self.yearindex.from_aligned( + self.semesterindex.compute_if_necessary( + starting_indexes.semesterindex, + &indexes.semesterindex_to_monthindex_count, + exit, + )?; + + self.yearindex.compute_if_necessary( starting_indexes.yearindex, - &self.monthindex, - &indexes.yearindex_to_first_monthindex, &indexes.yearindex_to_monthindex_count, exit, )?; - self.decadeindex.from_aligned( + self.decadeindex.compute_if_necessary( starting_indexes.decadeindex, - &self.yearindex, - &indexes.decadeindex_to_first_yearindex, &indexes.decadeindex_to_yearindex_count, exit, )?; @@ -258,6 +289,7 @@ where self.difficultyepoch.vecs(), self.monthindex.vecs(), self.quarterindex.vecs(), + self.semesterindex.vecs(), self.yearindex.vecs(), // self.halvingepoch.vecs(), self.decadeindex.vecs(), diff --git a/crates/brk_computer/src/vecs/grouped/mod.rs b/crates/brk_computer/src/vecs/grouped/mod.rs index 10457ca49..5c4e67968 100644 --- a/crates/brk_computer/src/vecs/grouped/mod.rs +++ b/crates/brk_computer/src/vecs/grouped/mod.rs @@ -1,21 +1,25 @@ -mod builder; +mod builder_computed; +mod builder_eager; mod from_dateindex; mod from_height; mod from_height_strict; mod from_txindex; mod ratio_from_dateindex; +mod source; mod r#type; mod value_from_dateindex; mod value_from_height; mod value_from_txindex; mod value_height; -pub use builder::*; +pub use builder_computed::*; +pub use builder_eager::*; pub use from_dateindex::*; pub use from_height::*; pub use from_height_strict::*; pub use from_txindex::*; pub use ratio_from_dateindex::*; +pub use source::*; use r#type::*; pub use value_from_dateindex::*; pub use value_from_height::*; diff --git a/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs index 0a0a81c84..eb674562e 100644 --- a/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/vecs/grouped/ratio_from_dateindex.rs @@ -4,16 +4,16 @@ use brk_core::{Date, DateIndex, Dollars, Result, StoredF32, Version}; use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{ - AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex, - VecIterator, + AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, Computation, EagerVec, Format, + StoredIndex, VecIterator, }; use crate::{ utils::get_percentile, - vecs::{Indexes, fetched, indexes}, + vecs::{Indexes, fetched, grouped::source::Source, indexes}, }; -use super::{ComputedVecsFromDateIndex, StorableVecGeneatorOptions}; +use super::{ComputedVecsFromDateIndex, EagerVecBuilderOptions}; #[derive(Clone)] pub struct ComputedRatioVecsFromDateIndex { @@ -64,20 +64,22 @@ impl ComputedRatioVecsFromDateIndex { pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, + computation: Computation, ) -> color_eyre::Result { - let options = StorableVecGeneatorOptions::default().add_last(); + let options = EagerVecBuilderOptions::default().add_last(); Ok(Self { - price: compute_source.then(|| { + price: source.is_compute().then(|| { ComputedVecsFromDateIndex::forced_import( path, name, - true, + Source::Compute, version + VERSION, format, + computation, options, ) .unwrap() @@ -85,297 +87,334 @@ impl ComputedRatioVecsFromDateIndex { ratio: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_sma"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_1w_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1w_sma"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_1m_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1m_sma"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_1y_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1y_sma"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_4y_sma: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_4y_sma"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1y_sma_momentum_oscillator"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_4y_sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_4y_sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_1y_sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1y_sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p99_9: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_9"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p99_5: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_5"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p99: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p1: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p0_5: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_5"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p0_1: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_1"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p1sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p2sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p2sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p3sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p3sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_m1sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m1sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_m2sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m2sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_m3sd: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m3sd"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p99_9_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_9_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p99_5_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_5_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p99_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p99_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p1_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p0_5_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_5_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p0_1_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p0_1_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p1sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p1sd_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p2sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p2sd_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_p3sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_p3sd_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_m1sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m1sd_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_m2sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m2sd_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_m3sd_as_price: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_m3sd_as_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_zscore: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_zscore"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_4y_zscore: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_4y_zscore"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, ratio_1y_zscore: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_ratio_1y_zscore"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, options, )?, }) diff --git a/crates/brk_computer/src/vecs/grouped/source.rs b/crates/brk_computer/src/vecs/grouped/source.rs new file mode 100644 index 000000000..d8886e4f5 --- /dev/null +++ b/crates/brk_computer/src/vecs/grouped/source.rs @@ -0,0 +1,51 @@ +use brk_vec::BoxedAnyIterableVec; + +#[derive(Clone)] +pub enum Source { + Compute, + None, + Vec(BoxedAnyIterableVec), +} + +impl Source { + pub fn is_compute(&self) -> bool { + matches!(self, Self::Compute) + } + + pub fn is_none(&self) -> bool { + matches!(self, Self::None) + } + + pub fn is_vec(&self) -> bool { + matches!(self, Self::Vec(_)) + } + + pub fn vec(self) -> Option> { + match self { + Self::Vec(v) => Some(v), + _ => None, + } + } +} + +impl From for Source { + fn from(value: bool) -> Self { + if value { Self::Compute } else { Self::None } + } +} + +impl From> for Source { + fn from(value: BoxedAnyIterableVec) -> Self { + Self::Vec(value) + } +} + +impl From>> for Source { + fn from(value: Option>) -> Self { + if let Some(v) = value { + Self::Vec(v) + } else { + Self::None + } + } +} diff --git a/crates/brk_computer/src/vecs/grouped/type.rs b/crates/brk_computer/src/vecs/grouped/type.rs index c98b6498f..357e6d6ba 100644 --- a/crates/brk_computer/src/vecs/grouped/type.rs +++ b/crates/brk_computer/src/vecs/grouped/type.rs @@ -1,13 +1,14 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use brk_vec::StoredType; pub trait ComputedType where - Self: StoredType + From + Div + Add + Ord, + Self: + StoredType + From + Div + Add + AddAssign + Ord, { } impl ComputedType for T where - T: StoredType + From + Div + Add + Ord + T: StoredType + From + Div + Add + AddAssign + Ord { } diff --git a/crates/brk_computer/src/vecs/grouped/value_from_dateindex.rs b/crates/brk_computer/src/vecs/grouped/value_from_dateindex.rs index 87195f2f1..721828224 100644 --- a/crates/brk_computer/src/vecs/grouped/value_from_dateindex.rs +++ b/crates/brk_computer/src/vecs/grouped/value_from_dateindex.rs @@ -3,11 +3,11 @@ use std::path::Path; use brk_core::{Bitcoin, DateIndex, Dollars, Result, Sats, Version}; use brk_exit::Exit; use brk_indexer::Indexer; -use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec}; +use brk_vec::{AnyCollectableVec, CollectableVec, Computation, EagerVec, Format, StoredVec}; use crate::vecs::{Indexes, fetched, grouped::ComputedVecsFromDateIndex, indexes}; -use super::StorableVecGeneatorOptions; +use super::{EagerVecBuilderOptions, Source}; #[derive(Clone)] pub struct ComputedValueVecsFromDateIndex { @@ -19,39 +19,44 @@ pub struct ComputedValueVecsFromDateIndex { const VERSION: Version = Version::ZERO; impl ComputedValueVecsFromDateIndex { + #[allow(clippy::too_many_arguments)] pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, - options: StorableVecGeneatorOptions, + computation: Computation, + options: EagerVecBuilderOptions, compute_dollars: bool, ) -> color_eyre::Result { Ok(Self { sats: ComputedVecsFromDateIndex::forced_import( path, name, - compute_source, + source, version + VERSION, format, + computation, options, )?, bitcoin: ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_in_btc"), - true, + Source::Compute, version + VERSION, format, + computation, options, )?, dollars: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( path, &format!("{name}_in_usd"), - true, + Source::Compute, version + VERSION, format, + computation, options, ) .unwrap() diff --git a/crates/brk_computer/src/vecs/grouped/value_from_height.rs b/crates/brk_computer/src/vecs/grouped/value_from_height.rs index 277dafaeb..41fec526f 100644 --- a/crates/brk_computer/src/vecs/grouped/value_from_height.rs +++ b/crates/brk_computer/src/vecs/grouped/value_from_height.rs @@ -3,11 +3,11 @@ use std::path::Path; use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version}; use brk_exit::Exit; use brk_indexer::Indexer; -use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec}; +use brk_vec::{AnyCollectableVec, CollectableVec, Computation, EagerVec, Format, StoredVec}; -use crate::vecs::{Indexes, fetched, indexes}; +use crate::vecs::{Indexes, fetched, grouped::Source, indexes}; -use super::{ComputedVecsFromHeight, StorableVecGeneatorOptions}; +use super::{ComputedVecsFromHeight, EagerVecBuilderOptions}; #[derive(Clone)] pub struct ComputedValueVecsFromHeight { @@ -19,39 +19,44 @@ pub struct ComputedValueVecsFromHeight { const VERSION: Version = Version::ZERO; impl ComputedValueVecsFromHeight { + #[allow(clippy::too_many_arguments)] pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, - options: StorableVecGeneatorOptions, + computation: Computation, + options: EagerVecBuilderOptions, compute_dollars: bool, ) -> color_eyre::Result { Ok(Self { sats: ComputedVecsFromHeight::forced_import( path, name, - compute_source, + source, version + VERSION, format, + computation, options, )?, bitcoin: ComputedVecsFromHeight::forced_import( path, &format!("{name}_in_btc"), - true, + Source::Compute, version + VERSION, format, + computation, options, )?, dollars: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( path, &format!("{name}_in_usd"), - true, + Source::Compute, version + VERSION, format, + computation, options, ) .unwrap() diff --git a/crates/brk_computer/src/vecs/grouped/value_from_txindex.rs b/crates/brk_computer/src/vecs/grouped/value_from_txindex.rs index ae6910614..32f6a3cdf 100644 --- a/crates/brk_computer/src/vecs/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/vecs/grouped/value_from_txindex.rs @@ -4,13 +4,13 @@ use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version}; use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{ - AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Computation, - ComputedVecFrom3, Format, LazyVecFrom1, StoredIndex, StoredVec, + AnyCollectableVec, CloneableAnyIterableVec, CollectableVec, Computation, ComputedVecFrom3, + Format, LazyVecFrom1, StoredIndex, StoredVec, }; -use crate::vecs::{Indexes, fetched, indexes}; +use crate::vecs::{Indexes, fetched, grouped::Source, indexes}; -use super::{ComputedVecsFromTxindex, StorableVecGeneatorOptions}; +use super::{ComputedVecsFromTxindex, EagerVecBuilderOptions}; #[derive(Clone)] pub struct ComputedValueVecsFromTxindex { @@ -41,14 +41,13 @@ impl ComputedValueVecsFromTxindex { path: &Path, name: &str, indexes: &indexes::Vecs, - source: Option>, + source: Source, version: Version, computation: Computation, format: Format, fetched: Option<&fetched::Vecs>, - options: StorableVecGeneatorOptions, + options: EagerVecBuilderOptions, ) -> color_eyre::Result { - let compute_source = source.is_none(); let compute_dollars = fetched.is_some(); let name_in_btc = format!("{name}_in_btc"); @@ -57,16 +56,19 @@ impl ComputedValueVecsFromTxindex { let sats = ComputedVecsFromTxindex::forced_import( path, name, - compute_source, + source.clone(), version + VERSION, format, + computation, options, )?; + let source_vec = source.vec(); + let bitcoin_txindex = LazyVecFrom1::init( &name_in_btc, version + VERSION, - source.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s), + source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s), |txindex: TxIndex, iter| { iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| { let sats = value.into_owned(); @@ -78,9 +80,10 @@ impl ComputedValueVecsFromTxindex { let bitcoin = ComputedVecsFromTxindex::forced_import( path, &name_in_btc, - false, + Source::None, version + VERSION, format, + computation, options, )?; @@ -124,9 +127,10 @@ impl ComputedValueVecsFromTxindex { ComputedVecsFromTxindex::forced_import( path, &name_in_usd, - false, + Source::None, version + VERSION, format, + computation, options, ) .unwrap() diff --git a/crates/brk_computer/src/vecs/grouped/value_height.rs b/crates/brk_computer/src/vecs/grouped/value_height.rs index b5ed7eaaa..bd2c34036 100644 --- a/crates/brk_computer/src/vecs/grouped/value_height.rs +++ b/crates/brk_computer/src/vecs/grouped/value_height.rs @@ -5,7 +5,7 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec}; -use crate::vecs::{Indexes, fetched, indexes}; +use crate::vecs::{Indexes, fetched, grouped::Source, indexes}; #[derive(Clone)] pub struct ComputedHeightValueVecs { @@ -20,13 +20,13 @@ impl ComputedHeightValueVecs { pub fn forced_import( path: &Path, name: &str, - compute_source: bool, + source: Source, version: Version, format: Format, compute_dollars: bool, ) -> color_eyre::Result { Ok(Self { - sats: compute_source.then(|| { + sats: source.is_compute().then(|| { EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format) .unwrap() }), diff --git a/crates/brk_computer/src/vecs/indexes.rs b/crates/brk_computer/src/vecs/indexes.rs index cd21acfc7..9c7ed5cda 100644 --- a/crates/brk_computer/src/vecs/indexes.rs +++ b/crates/brk_computer/src/vecs/indexes.rs @@ -5,8 +5,8 @@ use brk_core::{ InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2ABytes, P2MSOutputIndex, P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, P2PKHAddressIndex, P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, P2WPKHAddressIndex, - P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, StoredUsize, Timestamp, - TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex, + P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, SemesterIndex, StoredUsize, + Timestamp, TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex, }; use brk_exit::Exit; use brk_indexer::Indexer; @@ -50,6 +50,7 @@ pub struct Vecs { pub monthindex_to_first_dateindex: EagerVec, pub monthindex_to_monthindex: EagerVec, pub monthindex_to_quarterindex: EagerVec, + pub monthindex_to_semesterindex: EagerVec, pub monthindex_to_yearindex: EagerVec, pub opreturnindex_to_opreturnindex: ComputedVecFrom1, @@ -76,6 +77,9 @@ pub struct Vecs { pub quarterindex_to_first_monthindex: EagerVec, pub quarterindex_to_monthindex_count: EagerVec, pub quarterindex_to_quarterindex: EagerVec, + pub semesterindex_to_first_monthindex: EagerVec, + pub semesterindex_to_monthindex_count: EagerVec, + pub semesterindex_to_semesterindex: EagerVec, pub txindex_to_height: EagerVec, pub txindex_to_input_count: ComputedVecFrom2, @@ -413,6 +417,12 @@ impl Vecs { version + VERSION + Version::ZERO, format, )?, + monthindex_to_semesterindex: EagerVec::forced_import( + path, + "semesterindex", + version + VERSION + Version::ZERO, + format, + )?, monthindex_to_yearindex: EagerVec::forced_import( path, "yearindex", @@ -425,6 +435,12 @@ impl Vecs { version + VERSION + Version::ZERO, format, )?, + semesterindex_to_first_monthindex: EagerVec::forced_import( + path, + "first_monthindex", + version + VERSION + Version::ZERO, + format, + )?, weekindex_to_first_dateindex: EagerVec::forced_import( path, "first_dateindex", @@ -443,6 +459,12 @@ impl Vecs { version + VERSION + Version::ZERO, format, )?, + semesterindex_to_semesterindex: EagerVec::forced_import( + path, + "semesterindex", + version + VERSION + Version::ZERO, + format, + )?, weekindex_to_weekindex: EagerVec::forced_import( path, "weekindex", @@ -521,6 +543,12 @@ impl Vecs { version + VERSION + Version::ZERO, format, )?, + semesterindex_to_monthindex_count: EagerVec::forced_import( + path, + "monthindex_count", + version + VERSION + Version::ZERO, + format, + )?, yearindex_to_monthindex_count: EagerVec::forced_import( path, "monthindex_count", @@ -943,6 +971,45 @@ impl Vecs { exit, )?; + // --- + // SemesterIndex + // --- + + let starting_semesterindex = self + .monthindex_to_semesterindex + .into_iter() + .get_inner(starting_monthindex) + .unwrap_or_default(); + + self.monthindex_to_semesterindex.compute_from_index( + starting_monthindex, + &self.monthindex_to_first_dateindex, + exit, + )?; + + self.semesterindex_to_first_monthindex + .compute_inverse_more_to_less( + starting_monthindex, + &self.monthindex_to_semesterindex, + exit, + )?; + + // let semester_count = self.semesterindex_to_first_monthindex.len(); + + self.semesterindex_to_semesterindex.compute_from_index( + starting_semesterindex, + &self.semesterindex_to_first_monthindex, + exit, + )?; + + self.semesterindex_to_monthindex_count + .compute_count_from_indexes( + starting_semesterindex, + &self.semesterindex_to_first_monthindex, + &self.monthindex_to_monthindex, + exit, + )?; + // --- // YearIndex // --- @@ -1051,6 +1118,7 @@ impl Vecs { weekindex: starting_weekindex, monthindex: starting_monthindex, quarterindex: starting_quarterindex, + semesterindex: starting_semesterindex, yearindex: starting_yearindex, decadeindex: starting_decadeindex, difficultyepoch: starting_difficultyepoch, @@ -1088,6 +1156,7 @@ impl Vecs { &self.monthindex_to_first_dateindex, &self.monthindex_to_monthindex, &self.monthindex_to_quarterindex, + &self.monthindex_to_semesterindex, &self.monthindex_to_yearindex, &self.opreturnindex_to_opreturnindex, &self.outputindex_to_outputindex, @@ -1103,6 +1172,9 @@ impl Vecs { &self.quarterindex_to_first_monthindex, &self.quarterindex_to_monthindex_count, &self.quarterindex_to_quarterindex, + &self.semesterindex_to_first_monthindex, + &self.semesterindex_to_monthindex_count, + &self.semesterindex_to_semesterindex, &self.txindex_to_height, &self.txindex_to_txindex, &self.txindex_to_input_count, @@ -1126,6 +1198,7 @@ pub struct Indexes { pub weekindex: WeekIndex, pub monthindex: MonthIndex, pub quarterindex: QuarterIndex, + pub semesterindex: SemesterIndex, pub yearindex: YearIndex, pub decadeindex: DecadeIndex, pub difficultyepoch: DifficultyEpoch, @@ -1145,6 +1218,7 @@ impl Indexes { self.weekindex = WeekIndex::from(self.dateindex); self.monthindex = MonthIndex::from(self.dateindex); self.quarterindex = QuarterIndex::from(self.monthindex); + self.semesterindex = SemesterIndex::from(self.monthindex); self.yearindex = YearIndex::from(self.monthindex); self.decadeindex = DecadeIndex::from(self.dateindex); self.difficultyepoch = DifficultyEpoch::from(self.height); diff --git a/crates/brk_computer/src/vecs/market.rs b/crates/brk_computer/src/vecs/market.rs index 98e670660..a5b27ec71 100644 --- a/crates/brk_computer/src/vecs/market.rs +++ b/crates/brk_computer/src/vecs/market.rs @@ -5,11 +5,11 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, Computation, EagerVec, Format, StoredIndex, VecIterator}; +use crate::vecs::grouped::Source; + use super::{ Indexes, fetched, - grouped::{ - ComputedRatioVecsFromDateIndex, ComputedVecsFromDateIndex, StorableVecGeneatorOptions, - }, + grouped::{ComputedRatioVecsFromDateIndex, ComputedVecsFromDateIndex, EagerVecBuilderOptions}, indexes, transactions, }; @@ -165,7 +165,7 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, ) -> color_eyre::Result { Ok(Self { @@ -190,1043 +190,1174 @@ impl Vecs { indexes_to_marketcap: ComputedVecsFromDateIndex::forced_import( path, "marketcap", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_ath: ComputedVecsFromDateIndex::forced_import( path, "ath", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_drawdown: ComputedVecsFromDateIndex::forced_import( path, "drawdown", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_days_since_ath: ComputedVecsFromDateIndex::forced_import( path, "days_since_ath", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_max_days_between_aths: ComputedVecsFromDateIndex::forced_import( path, "max_days_between_aths", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_max_years_between_aths: ComputedVecsFromDateIndex::forced_import( path, "max_years_between_aths", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_1w_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "1w_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_8d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "8d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_13d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "13d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_21d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "21d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_1m_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "1m_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_34d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "34d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_55d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "55d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_89d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "89d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_144d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "144d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_200d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "200d_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_1y_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "1y_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_2y_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "2y_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_200w_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "200w_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, indexes_to_4y_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "4y_sma", - true, + Source::Compute, version + VERSION + Version::ZERO, format, + computation, )?, _1d_returns: ComputedVecsFromDateIndex::forced_import( path, "1d_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1w_returns: ComputedVecsFromDateIndex::forced_import( path, "1w_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1m_returns: ComputedVecsFromDateIndex::forced_import( path, "1m_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3m_returns: ComputedVecsFromDateIndex::forced_import( path, "3m_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6m_returns: ComputedVecsFromDateIndex::forced_import( path, "6m_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1y_returns: ComputedVecsFromDateIndex::forced_import( path, "1y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _2y_returns: ComputedVecsFromDateIndex::forced_import( path, "2y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3y_returns: ComputedVecsFromDateIndex::forced_import( path, "3y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _4y_returns: ComputedVecsFromDateIndex::forced_import( path, "4y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _5y_returns: ComputedVecsFromDateIndex::forced_import( path, "5y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6y_returns: ComputedVecsFromDateIndex::forced_import( path, "6y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _8y_returns: ComputedVecsFromDateIndex::forced_import( path, "8y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _10y_returns: ComputedVecsFromDateIndex::forced_import( path, "10y_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _2y_cagr: ComputedVecsFromDateIndex::forced_import( path, "2y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3y_cagr: ComputedVecsFromDateIndex::forced_import( path, "3y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _4y_cagr: ComputedVecsFromDateIndex::forced_import( path, "4y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _5y_cagr: ComputedVecsFromDateIndex::forced_import( path, "5y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6y_cagr: ComputedVecsFromDateIndex::forced_import( path, "6y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _8y_cagr: ComputedVecsFromDateIndex::forced_import( path, "8y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _10y_cagr: ComputedVecsFromDateIndex::forced_import( path, "10y_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1w_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "1w_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1m_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "1m_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3m_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "3m_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6m_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "6m_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "1y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _2y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "2y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "3y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _4y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "4y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _5y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "5y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "6y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _8y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "8y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _10y_dca_returns: ComputedVecsFromDateIndex::forced_import( path, "10y_dca_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _2y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "2y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "3y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _4y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "4y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _5y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "5y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "6y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _8y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "8y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _10y_dca_cagr: ComputedVecsFromDateIndex::forced_import( path, "10y_dca_cagr", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1w_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "1w_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1m_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "1m_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3m_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "3m_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6m_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "6m_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "1y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _2y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "2y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "3y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _4y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "4y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _5y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "5y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "6y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _8y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "8y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _10y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( path, "10y_dca_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_1d_ago: ComputedVecsFromDateIndex::forced_import( path, "price_1d_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_1w_ago: ComputedVecsFromDateIndex::forced_import( path, "price_1w_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_1m_ago: ComputedVecsFromDateIndex::forced_import( path, "price_1m_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_3m_ago: ComputedVecsFromDateIndex::forced_import( path, "price_3m_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_6m_ago: ComputedVecsFromDateIndex::forced_import( path, "price_6m_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_1y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_1y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_2y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_2y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_3y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_3y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_4y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_4y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_5y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_5y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_6y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_6y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_8y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_8y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, price_10y_ago: ComputedVecsFromDateIndex::forced_import( path, "price_10y_ago", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1w_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "1w_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1m_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "1m_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3m_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "3m_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6m_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "6m_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _1y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "1y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _2y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "2y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _3y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "3y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _4y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "4y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _5y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "5y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _6y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "6y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _8y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "8y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, _10y_dca_stack: ComputedVecsFromDateIndex::forced_import( path, "10y_dca_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2025_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2025_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2024_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2024_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2023_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2023_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2022_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2022_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2021_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2021_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2020_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2020_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2019_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2019_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2018_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2018_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2017_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2017_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2016_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2016_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2015_stack: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2015_stack", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2025_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2025_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2024_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2024_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2023_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2023_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2022_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2022_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2021_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2021_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2020_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2020_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2019_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2019_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2018_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2018_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2017_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2017_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2016_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2016_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2015_avg_price: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2015_avg_price", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2025_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2025_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2024_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2024_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2023_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2023_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2022_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2022_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2021_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2021_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2020_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2020_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2019_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2019_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2018_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2018_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2017_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2017_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2016_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2016_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, dca_class_2015_returns: ComputedVecsFromDateIndex::forced_import( path, "dca_class_2015_returns", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_200d_sma_x2_4: ComputedVecsFromDateIndex::forced_import( path, "200d_sma_x2_4", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_200d_sma_x0_8: ComputedVecsFromDateIndex::forced_import( path, "200d_sma_x0_8", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, }) } diff --git a/crates/brk_computer/src/vecs/mining.rs b/crates/brk_computer/src/vecs/mining.rs index 0dfc6e144..79a623ac3 100644 --- a/crates/brk_computer/src/vecs/mining.rs +++ b/crates/brk_computer/src/vecs/mining.rs @@ -5,9 +5,11 @@ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator}; +use crate::vecs::grouped::Source; + use super::{ Indexes, - grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions}, + grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, EagerVecBuilderOptions}, indexes, }; @@ -24,33 +26,36 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, ) -> color_eyre::Result { Ok(Self { indexes_to_difficulty: ComputedVecsFromHeight::forced_import( path, "difficulty", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import( path, "difficultyepoch", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import( path, "halvingepoch", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, }) } diff --git a/crates/brk_computer/src/vecs/stateful/address_cohort.rs b/crates/brk_computer/src/vecs/stateful/address_cohort.rs index 1e4f7a410..83ccf4a47 100644 --- a/crates/brk_computer/src/vecs/stateful/address_cohort.rs +++ b/crates/brk_computer/src/vecs/stateful/address_cohort.rs @@ -11,7 +11,7 @@ use crate::{ states::AddressCohortState, vecs::{ Indexes, fetched, - grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, + grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions, Source}, indexes, market, stateful::{ common, @@ -66,10 +66,11 @@ impl Vecs { indexes_to_address_count: ComputedVecsFromHeight::forced_import( path, &suffix("address_count"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, inner: common::Vecs::forced_import( path, diff --git a/crates/brk_computer/src/vecs/stateful/common.rs b/crates/brk_computer/src/vecs/stateful/common.rs index 36be93b05..50d27c7f5 100644 --- a/crates/brk_computer/src/vecs/stateful/common.rs +++ b/crates/brk_computer/src/vecs/stateful/common.rs @@ -6,7 +6,8 @@ use brk_core::{ use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{ - AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, Format, VecIterator, + AnyCollectableVec, AnyIterableVec, AnyVec, CloneableAnyIterableVec, Computation, EagerVec, + Format, VecIterator, }; use crate::{ @@ -16,7 +17,7 @@ use crate::{ grouped::{ ComputedHeightValueVecs, ComputedRatioVecsFromDateIndex, ComputedValueVecsFromDateIndex, ComputedVecsFromDateIndex, ComputedVecsFromHeight, - StorableVecGeneatorOptions, + EagerVecBuilderOptions, Source, }, indexes, market, }, @@ -132,7 +133,7 @@ impl Vecs { pub fn forced_import( path: &Path, cohort_name: Option<&str>, - _computation: Computation, + computation: Computation, format: Format, version: Version, fetched: Option<&fetched::Vecs>, @@ -144,8 +145,57 @@ impl Vecs { let suffix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{name}_{s}")); - Ok(Self { + let dateindex_to_supply_in_profit = compute_dollars.then(|| { + EagerVec::forced_import( + path, + &suffix("supply_in_profit"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }); + let dateindex_to_supply_even = compute_dollars.then(|| { + EagerVec::forced_import( + path, + &suffix("supply_even"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }); + + let dateindex_to_supply_in_loss = compute_dollars.then(|| { + EagerVec::forced_import( + path, + &suffix("supply_in_loss"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }); + + let dateindex_to_unrealized_profit = compute_dollars.then(|| { + EagerVec::forced_import( + path, + &suffix("unrealized_profit"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }); + + let dateindex_to_unrealized_loss = compute_dollars.then(|| { + EagerVec::forced_import( + path, + &suffix("unrealized_loss"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }); + + Ok(Self { height_to_supply_in_profit: compute_dollars.then(|| { EagerVec::forced_import( path, @@ -155,27 +205,20 @@ impl Vecs { ) .unwrap() }), - dateindex_to_supply_in_profit: compute_dollars.then(|| { - EagerVec::forced_import( - path, - &suffix("supply_in_profit"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }), indexes_to_supply_in_profit: compute_dollars.then(|| { ComputedValueVecsFromDateIndex::forced_import( path, &suffix("supply_in_profit"), - false, + dateindex_to_supply_in_profit.as_ref().map(|v | v.boxed_clone()).into(), version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, ) .unwrap() }), + dateindex_to_supply_in_profit, height_to_supply_even: compute_dollars.then(|| { EagerVec::forced_import( path, @@ -185,27 +228,20 @@ impl Vecs { ) .unwrap() }), - dateindex_to_supply_even: compute_dollars.then(|| { - EagerVec::forced_import( - path, - &suffix("supply_even"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }), indexes_to_supply_even: compute_dollars.then(|| { ComputedValueVecsFromDateIndex::forced_import( path, &suffix("supply_even"), - false, + dateindex_to_supply_even.as_ref().map(|v | v.boxed_clone()).into(), version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, ) .unwrap() }), + dateindex_to_supply_even, height_to_supply_in_loss: compute_dollars.then(|| { EagerVec::forced_import( path, @@ -215,27 +251,20 @@ impl Vecs { ) .unwrap() }), - dateindex_to_supply_in_loss: compute_dollars.then(|| { - EagerVec::forced_import( - path, - &suffix("supply_in_loss"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }), indexes_to_supply_in_loss: compute_dollars.then(|| { ComputedValueVecsFromDateIndex::forced_import( path, &suffix("supply_in_loss"), - false, + dateindex_to_supply_in_loss.as_ref().map(|v | v.boxed_clone()).into(), version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, ) .unwrap() }), + dateindex_to_supply_in_loss, height_to_unrealized_profit: compute_dollars.then(|| { EagerVec::forced_import( path, @@ -245,26 +274,19 @@ impl Vecs { ) .unwrap() }), - dateindex_to_unrealized_profit: compute_dollars.then(|| { - EagerVec::forced_import( - path, - &suffix("unrealized_profit"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }), indexes_to_unrealized_profit: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( path, &suffix("unrealized_profit"), - false, + dateindex_to_unrealized_profit.as_ref().map(|v | v.boxed_clone()).into(), version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), + dateindex_to_unrealized_profit, height_to_unrealized_loss: compute_dollars.then(|| { EagerVec::forced_import( path, @@ -292,26 +314,19 @@ impl Vecs { ) .unwrap() }), - dateindex_to_unrealized_loss: compute_dollars.then(|| { - EagerVec::forced_import( - path, - &suffix("unrealized_loss"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }), indexes_to_unrealized_loss: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( path, &suffix("unrealized_loss"), - false, + dateindex_to_unrealized_loss.as_ref().map(|v | v.boxed_clone()).into(), version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), + dateindex_to_unrealized_loss, height_to_realized_cap: compute_dollars.then(|| { EagerVec::forced_import( path, @@ -325,10 +340,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("realized_cap"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -336,10 +352,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("min_price_paid"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -347,10 +364,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("max_price_paid"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -363,7 +381,7 @@ impl Vecs { height_to_supply_value: ComputedHeightValueVecs::forced_import( path, &suffix("supply"), - false, + Source::None, version + VERSION + Version::ZERO, format, compute_dollars, @@ -371,10 +389,11 @@ impl Vecs { indexes_to_supply: ComputedValueVecsFromDateIndex::forced_import( path, &suffix("supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, )?, height_to_utxo_count: EagerVec::forced_import( @@ -386,19 +405,21 @@ impl Vecs { indexes_to_utxo_count: ComputedVecsFromHeight::forced_import( path, &suffix("utxo_count"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_realized_price: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( path, &suffix("realized_price"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -406,9 +427,10 @@ impl Vecs { ComputedRatioVecsFromDateIndex::forced_import( path, &suffix("realized_price"), - false, + Source::None, version + VERSION + Version::ZERO, format, + computation, ) .unwrap() }), @@ -425,10 +447,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("realized_profit"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_sum() .add_cumulative(), ) @@ -447,10 +470,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("realized_loss"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_sum() .add_cumulative(), ) @@ -460,10 +484,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("negative_realized_loss"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_sum().add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), ) .unwrap() }), @@ -480,10 +505,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("value_created"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -491,10 +517,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("realized_value"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -511,10 +538,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("adjusted_value_created"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -531,10 +559,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("value_destroyed"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -551,10 +580,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("adjusted_value_destroyed"), - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -562,10 +592,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("realized_cap_30d_change"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -573,10 +604,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("net_realized_profit_and_loss"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_sum() .add_cumulative(), ) @@ -612,7 +644,7 @@ impl Vecs { height_to_halved_supply_value: ComputedHeightValueVecs::forced_import( path, &suffix("halved_supply"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, compute_dollars, @@ -620,10 +652,11 @@ impl Vecs { indexes_to_halved_supply: ComputedValueVecsFromDateIndex::forced_import( path, &suffix("halved_supply"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, )?, height_to_negative_unrealized_loss: compute_dollars.then(|| { @@ -639,10 +672,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("negative_unrealized_loss"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -659,10 +693,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("net_unrealized_profit_and_loss"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -682,10 +717,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("net_unrealized_profit_and_loss_relative_to_market_cap"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }, @@ -694,10 +730,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("realized_profit_relative_to_realized_cap"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -705,10 +742,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("realized_loss_relative_to_realized_cap"), - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }), @@ -717,10 +755,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("net_realized_profit_and_loss_relative_to_realized_cap"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_sum(), + computation, + EagerVecBuilderOptions::default().add_sum(), ) .unwrap() }, @@ -729,7 +768,7 @@ impl Vecs { ComputedHeightValueVecs::forced_import( path, &suffix("supply_even"), - false, + Source::None, version + VERSION + Version::ZERO, format, compute_dollars, @@ -740,7 +779,7 @@ impl Vecs { ComputedHeightValueVecs::forced_import( path, &suffix("supply_in_loss"), - false, + Source::None, version + VERSION + Version::ZERO, format, compute_dollars, @@ -751,7 +790,7 @@ impl Vecs { ComputedHeightValueVecs::forced_import( path, &suffix("supply_in_profit"), - false, + Source::None, version + VERSION + Version::ZERO, format, compute_dollars, @@ -789,10 +828,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("supply_even_relative_to_own_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -800,10 +840,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("supply_in_loss_relative_to_own_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -811,10 +852,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("supply_in_profit_relative_to_own_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -822,10 +864,11 @@ impl Vecs { ComputedVecsFromHeight::forced_import( path, &suffix("supply_relative_to_circulating_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -868,10 +911,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("supply_even_relative_to_circulating_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -881,10 +925,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("supply_in_loss_relative_to_circulating_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -894,10 +939,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("supply_in_profit_relative_to_circulating_supply"), - true, + Source::Compute, version + VERSION + Version::ONE, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), ) .unwrap() }), @@ -916,27 +962,30 @@ impl Vecs { indexes_to_coinblocks_destroyed: ComputedVecsFromHeight::forced_import( path, &suffix("coinblocks_destroyed"), - true, + Source::Compute, version + VERSION + Version::TWO, format, - StorableVecGeneatorOptions::default().add_sum().add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_coindays_destroyed: ComputedVecsFromHeight::forced_import( path, &suffix("coindays_destroyed"), - true, + Source::Compute, version + VERSION + Version::TWO, format, - StorableVecGeneatorOptions::default().add_sum().add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_net_realized_profit_and_loss_cumulative_30d_change: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( path, &suffix("net_realized_profit_and_loss_cumulative_30d_change"), - true, + Source::Compute, version + VERSION + Version::new(3), format, - StorableVecGeneatorOptions::default().add_last() + computation, + EagerVecBuilderOptions::default().add_last() ) .unwrap() }), @@ -944,10 +993,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap"), - true, + Source::Compute, version + VERSION + Version::new(3), format, - StorableVecGeneatorOptions::default().add_last() + computation, + EagerVecBuilderOptions::default().add_last() ) .unwrap() }), @@ -955,10 +1005,11 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( path, &suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap"), - true, + Source::Compute, version + VERSION + Version::new(3), format, - StorableVecGeneatorOptions::default().add_last() + computation, + EagerVecBuilderOptions::default().add_last() ) .unwrap() }), diff --git a/crates/brk_computer/src/vecs/stateful/mod.rs b/crates/brk_computer/src/vecs/stateful/mod.rs index dbfbbea23..d24b9f795 100644 --- a/crates/brk_computer/src/vecs/stateful/mod.rs +++ b/crates/brk_computer/src/vecs/stateful/mod.rs @@ -18,7 +18,7 @@ use crate::{ BlockState, SupplyState, Transacted, stores::Stores, vecs::{ - grouped::ComputedVecsFromHeight, + grouped::{ComputedVecsFromHeight, Source}, market, stateful::{ addresstype_to_addresscount::AddressTypeToAddressCount, @@ -31,7 +31,7 @@ use crate::{ use super::{ Indexes, fetched, - grouped::{ComputedValueVecsFromHeight, StorableVecGeneatorOptions}, + grouped::{ComputedValueVecsFromHeight, EagerVecBuilderOptions}, indexes, transactions, }; @@ -78,7 +78,7 @@ impl Vecs { pub fn forced_import( path: &Path, version: Version, - _computation: Computation, + computation: Computation, format: Format, fetched: Option<&fetched::Vecs>, ) -> color_eyre::Result { @@ -106,10 +106,11 @@ impl Vecs { indexes_to_unspendable_supply: ComputedValueVecsFromHeight::forced_import( path, "unspendable_supply", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, )?, height_to_opreturn_supply: EagerVec::forced_import( @@ -121,27 +122,30 @@ impl Vecs { indexes_to_opreturn_supply: ComputedValueVecsFromHeight::forced_import( path, "opreturn_supply", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), compute_dollars, )?, indexes_to_address_count: ComputedVecsFromHeight::forced_import( path, "address_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import( path, "empty_address_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from( ByAddressType { @@ -252,66 +256,74 @@ impl Vecs { p2pk65: ComputedVecsFromHeight::forced_import( path, "p2pk65_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2pk33: ComputedVecsFromHeight::forced_import( path, "p2pk33_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2pkh: ComputedVecsFromHeight::forced_import( path, "p2pkh_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2sh: ComputedVecsFromHeight::forced_import( path, "p2sh_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2wpkh: ComputedVecsFromHeight::forced_import( path, "p2wpkh_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2wsh: ComputedVecsFromHeight::forced_import( path, "p2wsh_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2tr: ComputedVecsFromHeight::forced_import( path, "p2tr_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2a: ComputedVecsFromHeight::forced_import( path, "p2a_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, }, ), @@ -320,73 +332,81 @@ impl Vecs { p2pk65: ComputedVecsFromHeight::forced_import( path, "p2pk65_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2pk33: ComputedVecsFromHeight::forced_import( path, "p2pk33_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2pkh: ComputedVecsFromHeight::forced_import( path, "p2pkh_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2sh: ComputedVecsFromHeight::forced_import( path, "p2sh_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2wpkh: ComputedVecsFromHeight::forced_import( path, "p2wpkh_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2wsh: ComputedVecsFromHeight::forced_import( path, "p2wsh_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2tr: ComputedVecsFromHeight::forced_import( path, "p2tr_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, p2a: ComputedVecsFromHeight::forced_import( path, "p2a_empty_address_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, }, ), utxo_vecs: utxo_cohorts::Vecs::forced_import( path, version, - _computation, + computation, format, fetched, &states_path, @@ -394,7 +414,7 @@ impl Vecs { address_vecs: address_cohorts::Vecs::forced_import( path, version, - _computation, + computation, format, fetched, &states_path, @@ -1302,34 +1322,37 @@ impl Vecs { // Capped as external drives (even thunderbolt 4 SSDs) can be overwhelmed let chunk_size = (vecs.len() as f64 / 3.0).ceil() as usize; - vecs.into_par_iter().chunks(chunk_size).try_for_each(|v| { - v.into_iter().try_for_each(|either| match either { - Either::Left(v) => v.compute_rest_part2( - indexer, - indexes, - fetched, - starting_indexes, - market, - &height_to_supply, - dateindex_to_supply_ref, - height_to_realized_cap_ref, - dateindex_to_realized_cap_ref, - exit, - ), - Either::Right(v) => v.compute_rest_part2( - indexer, - indexes, - fetched, - starting_indexes, - market, - &height_to_supply, - dateindex_to_supply_ref, - height_to_realized_cap_ref, - dateindex_to_realized_cap_ref, - exit, - ), - }) - })?; + vecs.into_par_iter() + // .into_iter() + .chunks(chunk_size) + .try_for_each(|v| { + v.into_iter().try_for_each(|either| match either { + Either::Left(v) => v.compute_rest_part2( + indexer, + indexes, + fetched, + starting_indexes, + market, + &height_to_supply, + dateindex_to_supply_ref, + height_to_realized_cap_ref, + dateindex_to_realized_cap_ref, + exit, + ), + Either::Right(v) => v.compute_rest_part2( + indexer, + indexes, + fetched, + starting_indexes, + market, + &height_to_supply, + dateindex_to_supply_ref, + height_to_realized_cap_ref, + dateindex_to_realized_cap_ref, + exit, + ), + }) + })?; self.indexes_to_unspendable_supply.compute_rest( indexer, diff --git a/crates/brk_computer/src/vecs/transactions.rs b/crates/brk_computer/src/vecs/transactions.rs index 9872640c3..11380ed90 100644 --- a/crates/brk_computer/src/vecs/transactions.rs +++ b/crates/brk_computer/src/vecs/transactions.rs @@ -11,11 +11,13 @@ use brk_vec::{ ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, Format, StoredIndex, VecIterator, }; +use crate::vecs::grouped::Source; + use super::{ Indexes, fetched, grouped::{ ComputedValueVecsFromHeight, ComputedValueVecsFromTxindex, ComputedVecsFromHeight, - ComputedVecsFromTxindex, StorableVecGeneatorOptions, + ComputedVecsFromTxindex, EagerVecBuilderOptions, }, indexes, }; @@ -237,7 +239,8 @@ impl Vecs { // true, // version + VERSION + Version::ZERO, // format, - // StorableVecGeneatorOptions::default() + // computation, + // StorableVecGeneatorOptions::default() // .add_average() // .add_sum() // .add_cumulative(), @@ -286,7 +289,8 @@ impl Vecs { // true, // version + VERSION + Version::ZERO, // format, - // StorableVecGeneatorOptions::default() + // computation, + // StorableVecGeneatorOptions::default() // .add_average() // .add_sum() // .add_cumulative(), @@ -339,10 +343,11 @@ impl Vecs { indexes_to_tx_count: ComputedVecsFromHeight::forced_import( path, "tx_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -352,10 +357,11 @@ impl Vecs { indexes_to_input_count: ComputedVecsFromTxindex::forced_import( path, "input_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -365,10 +371,11 @@ impl Vecs { indexes_to_output_count: ComputedVecsFromTxindex::forced_import( path, "output_count", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -378,43 +385,40 @@ impl Vecs { indexes_to_tx_v1: ComputedVecsFromHeight::forced_import( path, "tx_v1", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_tx_v2: ComputedVecsFromHeight::forced_import( path, "tx_v2", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_tx_v3: ComputedVecsFromHeight::forced_import( path, "tx_v3", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), )?, indexes_to_fee: ComputedValueVecsFromTxindex::forced_import( path, "fee", indexes, - Some(txindex_to_fee.boxed_clone()), + Source::Vec(txindex_to_fee.boxed_clone()), version + VERSION + Version::ZERO, computation, format, fetched, - StorableVecGeneatorOptions::default() + EagerVecBuilderOptions::default() .add_sum() .add_cumulative() .add_percentiles() @@ -424,10 +428,11 @@ impl Vecs { indexes_to_feerate: ComputedVecsFromTxindex::forced_import( path, "feerate", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_percentiles() .add_minmax() .add_average(), @@ -435,10 +440,11 @@ impl Vecs { indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import( path, "tx_vsize", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_percentiles() .add_minmax() .add_average(), @@ -446,10 +452,11 @@ impl Vecs { indexes_to_tx_weight: ComputedVecsFromTxindex::forced_import( path, "tx_weight", - false, + Source::None, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_percentiles() .add_minmax() .add_average(), @@ -457,10 +464,11 @@ impl Vecs { indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import( path, "subsidy", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_percentiles() .add_sum() .add_cumulative() @@ -471,10 +479,11 @@ impl Vecs { indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import( path, "coinbase", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_sum() .add_cumulative() .add_percentiles() @@ -485,21 +494,21 @@ impl Vecs { indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight::forced_import( path, "unclaimed_rewards", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() - .add_sum() - .add_cumulative(), + computation, + EagerVecBuilderOptions::default().add_sum().add_cumulative(), compute_dollars, )?, indexes_to_p2a_count: ComputedVecsFromHeight::forced_import( path, "p2a_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -509,10 +518,11 @@ impl Vecs { indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import( path, "p2ms_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -522,10 +532,11 @@ impl Vecs { indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import( path, "p2pk33_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -535,10 +546,11 @@ impl Vecs { indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import( path, "p2pk65_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -548,10 +560,11 @@ impl Vecs { indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import( path, "p2pkh_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -561,10 +574,11 @@ impl Vecs { indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import( path, "p2sh_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -574,10 +588,11 @@ impl Vecs { indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import( path, "p2tr_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -587,10 +602,11 @@ impl Vecs { indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import( path, "p2wpkh_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -600,10 +616,11 @@ impl Vecs { indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import( path, "p2wsh_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -613,10 +630,11 @@ impl Vecs { indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import( path, "opreturn_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -626,10 +644,11 @@ impl Vecs { indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import( path, "unknownoutput_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -639,10 +658,11 @@ impl Vecs { indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import( path, "emptyoutput_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default() + computation, + EagerVecBuilderOptions::default() .add_average() .add_minmax() .add_percentiles() @@ -652,10 +672,11 @@ impl Vecs { indexes_to_exact_utxo_count: ComputedVecsFromHeight::forced_import( path, "exact_utxo_count", - true, + Source::Compute, version + VERSION + Version::ZERO, format, - StorableVecGeneatorOptions::default().add_last(), + computation, + EagerVecBuilderOptions::default().add_last(), )?, txindex_to_is_coinbase, inputindex_to_value, diff --git a/crates/brk_core/src/structs/bitcoin.rs b/crates/brk_core/src/structs/bitcoin.rs index 85f911a74..84257c818 100644 --- a/crates/brk_core/src/structs/bitcoin.rs +++ b/crates/brk_core/src/structs/bitcoin.rs @@ -1,6 +1,6 @@ use std::{ cmp::Ordering, - ops::{Add, Div, Mul}, + ops::{Add, AddAssign, Div, Mul}, }; use serde::Serialize; @@ -20,6 +20,12 @@ impl Add for Bitcoin { } } +impl AddAssign for Bitcoin { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl Mul for Bitcoin { type Output = Self; fn mul(self, rhs: Self) -> Self::Output { diff --git a/crates/brk_core/src/structs/date.rs b/crates/brk_core/src/structs/date.rs index e3ed7398c..f1fe488be 100644 --- a/crates/brk_core/src/structs/date.rs +++ b/crates/brk_core/src/structs/date.rs @@ -31,6 +31,10 @@ impl Date { pub fn day(&self) -> u8 { (self.0 % 1_00) as u8 } + + pub fn into_jiff(self) -> Date_ { + self.into() + } } impl Default for Date { diff --git a/crates/brk_core/src/structs/dateindex.rs b/crates/brk_core/src/structs/dateindex.rs index 7c079ef26..8ca089287 100644 --- a/crates/brk_core/src/structs/dateindex.rs +++ b/crates/brk_core/src/structs/dateindex.rs @@ -3,11 +3,14 @@ use std::{ ops::{Add, Rem}, }; +use jiff::Span; use serde::Serialize; -// use color_eyre::eyre::eyre; use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; -use crate::{CheckedSub, Error, Printable}; +use crate::{ + CheckedSub, DecadeIndex, Error, FromCoarserIndex, MonthIndex, Printable, QuarterIndex, + SemesterIndex, WeekIndex, YearIndex, +}; use super::Date; @@ -103,3 +106,135 @@ impl Printable for DateIndex { &["d", "date", "dateindex"] } } + +impl FromCoarserIndex for DateIndex { + fn min_from(coarser: WeekIndex) -> usize { + let coarser = usize::from(coarser); + if coarser == 0 { + 0 + } else if coarser == 1 { + 1 + } else { + 4 + (coarser - 1) * 7 + } + } + + fn max_from(coarser: WeekIndex) -> usize { + let coarser = usize::from(coarser); + if coarser == 0 { + 0 + } else if coarser == 1 { + 3 + } else { + 3 + coarser * 7 + } + } +} + +impl FromCoarserIndex for DateIndex { + fn min_from(coarser: MonthIndex) -> usize { + let coarser = u16::from(coarser); + if coarser == 0 { + 0 + } else { + let d = Date::new(2009, 1, 1) + .into_jiff() + .checked_add(Span::new().months(coarser)) + .unwrap(); + DateIndex::try_from(Date::from(d)).unwrap().into() + } + } + + fn max_from(coarser: MonthIndex) -> usize { + let d = Date::new(2009, 1, 31) + .into_jiff() + .checked_add(Span::new().months(u16::from(coarser))) + .unwrap(); + DateIndex::try_from(Date::from(d)).unwrap().into() + } +} + +impl FromCoarserIndex for DateIndex { + fn min_from(coarser: QuarterIndex) -> usize { + let coarser = u16::from(coarser); + if coarser == 0 { + 0 + } else { + let d = Date::new(2009, 1, 1) + .into_jiff() + .checked_add(Span::new().months(3 * coarser)) + .unwrap(); + DateIndex::try_from(Date::from(d)).unwrap().into() + } + } + + fn max_from(coarser: QuarterIndex) -> usize { + let d = Date::new(2009, 3, 31) + .into_jiff() + .checked_add(Span::new().months(3 * u16::from(coarser))) + .unwrap(); + DateIndex::try_from(Date::from(d)).unwrap().into() + } +} + +impl FromCoarserIndex for DateIndex { + fn min_from(coarser: SemesterIndex) -> usize { + let coarser = u16::from(coarser); + if coarser == 0 { + 0 + } else { + let d = Date::new(2009, 1, 1) + .into_jiff() + .checked_add(Span::new().months(6 * coarser)) + .unwrap(); + DateIndex::try_from(Date::from(d)).unwrap().into() + } + } + + fn max_from(coarser: SemesterIndex) -> usize { + let d = Date::new(2009, 5, 31) + .into_jiff() + .checked_add(Span::new().months(1 + 6 * u16::from(coarser))) + .unwrap(); + DateIndex::try_from(Date::from(d)).unwrap().into() + } +} + +impl FromCoarserIndex for DateIndex { + fn min_from(coarser: YearIndex) -> usize { + let coarser = u16::from(coarser); + if coarser == 0 { + 0 + } else { + Self::try_from(Date::new(2009 + coarser, 1, 1)) + .unwrap() + .into() + } + } + + fn max_from(coarser: YearIndex) -> usize { + Self::try_from(Date::new(2009 + u16::from(coarser), 12, 31)) + .unwrap() + .into() + } +} + +impl FromCoarserIndex for DateIndex { + fn min_from(coarser: DecadeIndex) -> usize { + let coarser = u16::from(coarser); + if coarser == 0 { + 0 + } else { + Self::try_from(Date::new(2000 + 10 * coarser, 1, 1)) + .unwrap() + .into() + } + } + + fn max_from(coarser: DecadeIndex) -> usize { + let coarser = u16::from(coarser); + Self::try_from(Date::new(2009 + (10 * coarser), 12, 31)) + .unwrap() + .into() + } +} diff --git a/crates/brk_core/src/structs/decadeindex.rs b/crates/brk_core/src/structs/decadeindex.rs index 5b6e806e6..d0b01002a 100644 --- a/crates/brk_core/src/structs/decadeindex.rs +++ b/crates/brk_core/src/structs/decadeindex.rs @@ -31,6 +31,18 @@ impl From for DecadeIndex { } } +impl From for u8 { + fn from(value: DecadeIndex) -> Self { + value.0 + } +} + +impl From for u16 { + fn from(value: DecadeIndex) -> Self { + value.0 as u16 + } +} + impl From for DecadeIndex { fn from(value: usize) -> Self { Self(value as u8) diff --git a/crates/brk_core/src/structs/difficultyepoch.rs b/crates/brk_core/src/structs/difficultyepoch.rs index 3886ab9a6..fa5772a4f 100644 --- a/crates/brk_core/src/structs/difficultyepoch.rs +++ b/crates/brk_core/src/structs/difficultyepoch.rs @@ -1,6 +1,6 @@ use std::{ fmt::Debug, - ops::{Add, Div}, + ops::{Add, AddAssign, Div}, }; use serde::{Deserialize, Serialize}; @@ -54,6 +54,12 @@ impl Add for DifficultyEpoch { } } +impl AddAssign for DifficultyEpoch { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl Add for DifficultyEpoch { type Output = Self; diff --git a/crates/brk_core/src/structs/feerate.rs b/crates/brk_core/src/structs/feerate.rs index 35b1cd767..d22c10f90 100644 --- a/crates/brk_core/src/structs/feerate.rs +++ b/crates/brk_core/src/structs/feerate.rs @@ -1,6 +1,6 @@ use std::{ cmp::Ordering, - ops::{Add, Div}, + ops::{Add, AddAssign, Div}, }; use serde::Serialize; @@ -35,6 +35,12 @@ impl Add for Feerate { } } +impl AddAssign for Feerate { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl Div for Feerate { type Output = Self; fn div(self, rhs: usize) -> Self::Output { diff --git a/crates/brk_core/src/structs/halvingepoch.rs b/crates/brk_core/src/structs/halvingepoch.rs index 66cf19401..cb2e3866e 100644 --- a/crates/brk_core/src/structs/halvingepoch.rs +++ b/crates/brk_core/src/structs/halvingepoch.rs @@ -1,6 +1,6 @@ use std::{ fmt::Debug, - ops::{Add, Div}, + ops::{Add, AddAssign, Div}, }; use serde::{Deserialize, Serialize}; @@ -60,6 +60,12 @@ impl Add for HalvingEpoch { } } +impl AddAssign for HalvingEpoch { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl Add for HalvingEpoch { type Output = Self; diff --git a/crates/brk_core/src/structs/mod.rs b/crates/brk_core/src/structs/mod.rs index e2d95742e..e21c12922 100644 --- a/crates/brk_core/src/structs/mod.rs +++ b/crates/brk_core/src/structs/mod.rs @@ -33,6 +33,7 @@ mod p2wshaddressindex; mod quarterindex; mod rawlocktime; mod sats; +mod semesterindex; mod stored_f32; mod stored_f64; mod stored_u32; @@ -90,6 +91,7 @@ pub use p2wshaddressindex::*; pub use quarterindex::*; pub use rawlocktime::*; pub use sats::*; +pub use semesterindex::*; pub use stored_f32::*; pub use stored_f64::*; pub use stored_u8::*; diff --git a/crates/brk_core/src/structs/monthindex.rs b/crates/brk_core/src/structs/monthindex.rs index d99f95b72..7c4e88b71 100644 --- a/crates/brk_core/src/structs/monthindex.rs +++ b/crates/brk_core/src/structs/monthindex.rs @@ -31,6 +31,12 @@ impl From for MonthIndex { } } +impl From for u16 { + fn from(value: MonthIndex) -> Self { + value.0 + } +} + impl From for MonthIndex { fn from(value: usize) -> Self { Self(value as u16) diff --git a/crates/brk_core/src/structs/ohlc.rs b/crates/brk_core/src/structs/ohlc.rs index 7afaceda2..4e13773b4 100644 --- a/crates/brk_core/src/structs/ohlc.rs +++ b/crates/brk_core/src/structs/ohlc.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use derive_deref::{Deref, DerefMut}; use serde::{Serialize, Serializer, ser::SerializeTuple}; @@ -236,6 +236,15 @@ where } } +impl AddAssign for Open +where + T: Add + Clone, +{ + fn add_assign(&mut self, rhs: Self) { + **self = self.0.clone() + rhs.0 + } +} + impl Div for Open where T: Div, @@ -324,6 +333,15 @@ where } } +impl AddAssign for High +where + T: Add + Clone, +{ + fn add_assign(&mut self, rhs: Self) { + **self = self.0.clone() + rhs.0 + } +} + impl Div for High where T: Div, @@ -412,6 +430,15 @@ where } } +impl AddAssign for Low +where + T: Add + Clone, +{ + fn add_assign(&mut self, rhs: Self) { + **self = self.0.clone() + rhs.0 + } +} + impl Div for Low where T: Div, @@ -515,6 +542,15 @@ where } } +impl AddAssign for Close +where + T: Add + Clone, +{ + fn add_assign(&mut self, rhs: Self) { + **self = self.0.clone() + rhs.0 + } +} + impl Div for Close where T: Div, diff --git a/crates/brk_core/src/structs/quarterindex.rs b/crates/brk_core/src/structs/quarterindex.rs index 6f77bb7a5..a7e65d9c9 100644 --- a/crates/brk_core/src/structs/quarterindex.rs +++ b/crates/brk_core/src/structs/quarterindex.rs @@ -37,6 +37,12 @@ impl From for QuarterIndex { } } +impl From for u16 { + fn from(value: QuarterIndex) -> Self { + value.0 + } +} + impl From for usize { fn from(value: QuarterIndex) -> Self { value.0 as usize diff --git a/crates/brk_core/src/structs/semesterindex.rs b/crates/brk_core/src/structs/semesterindex.rs new file mode 100644 index 000000000..6de6c428b --- /dev/null +++ b/crates/brk_core/src/structs/semesterindex.rs @@ -0,0 +1,80 @@ +use std::{fmt::Debug, ops::Add}; + +use serde::{Deserialize, Serialize}; +use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; + +use crate::{CheckedSub, Printable}; + +use super::MonthIndex; + +#[derive( + Debug, + Clone, + Copy, + PartialEq, + Eq, + PartialOrd, + Ord, + Default, + Serialize, + Deserialize, + FromBytes, + Immutable, + IntoBytes, + KnownLayout, +)] +pub struct SemesterIndex(u16); + +impl From for SemesterIndex { + fn from(value: u16) -> Self { + Self(value) + } +} + +impl From for SemesterIndex { + fn from(value: usize) -> Self { + Self(value as u16) + } +} + +impl From for u16 { + fn from(value: SemesterIndex) -> Self { + value.0 + } +} + +impl From for usize { + fn from(value: SemesterIndex) -> Self { + value.0 as usize + } +} + +impl Add for SemesterIndex { + type Output = Self; + + fn add(self, rhs: usize) -> Self::Output { + Self::from(self.0 + rhs as u16) + } +} + +impl From for SemesterIndex { + fn from(value: MonthIndex) -> Self { + Self((usize::from(value) / 6) as u16) + } +} + +impl CheckedSub for SemesterIndex { + fn checked_sub(self, rhs: Self) -> Option { + self.0.checked_sub(rhs.0).map(Self) + } +} + +impl Printable for SemesterIndex { + fn to_string() -> &'static str { + "semesterindex" + } + + fn to_possible_strings() -> &'static [&'static str] { + &["s", "semester", "semesterindex"] + } +} diff --git a/crates/brk_core/src/structs/stored_f32.rs b/crates/brk_core/src/structs/stored_f32.rs index 8da7e21ad..a50799a93 100644 --- a/crates/brk_core/src/structs/stored_f32.rs +++ b/crates/brk_core/src/structs/stored_f32.rs @@ -1,7 +1,7 @@ use core::panic; use std::{ cmp::Ordering, - ops::{Add, Div, Mul, Sub}, + ops::{Add, AddAssign, Div, Mul, Sub}, }; use derive_deref::Deref; @@ -70,6 +70,12 @@ impl Add for StoredF32 { } } +impl AddAssign for StoredF32 { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for f32 { fn from(value: StoredF32) -> Self { value.0 diff --git a/crates/brk_core/src/structs/stored_f64.rs b/crates/brk_core/src/structs/stored_f64.rs index 90c89bb9e..f22ff993a 100644 --- a/crates/brk_core/src/structs/stored_f64.rs +++ b/crates/brk_core/src/structs/stored_f64.rs @@ -1,7 +1,7 @@ use std::{ cmp::Ordering, f64, - ops::{Add, Div, Mul}, + ops::{Add, AddAssign, Div, Mul}, }; use derive_deref::Deref; @@ -65,6 +65,12 @@ impl Add for StoredF64 { } } +impl AddAssign for StoredF64 { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for f64 { fn from(value: StoredF64) -> Self { value.0 diff --git a/crates/brk_core/src/structs/stored_u32.rs b/crates/brk_core/src/structs/stored_u32.rs index de9569069..b1e4b5d96 100644 --- a/crates/brk_core/src/structs/stored_u32.rs +++ b/crates/brk_core/src/structs/stored_u32.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; @@ -73,6 +73,12 @@ impl Add for StoredU32 { } } +impl AddAssign for StoredU32 { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for StoredU32 { fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { diff --git a/crates/brk_core/src/structs/stored_u64.rs b/crates/brk_core/src/structs/stored_u64.rs index 1edd718d8..82a8908dc 100644 --- a/crates/brk_core/src/structs/stored_u64.rs +++ b/crates/brk_core/src/structs/stored_u64.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; @@ -65,6 +65,12 @@ impl Add for StoredU64 { } } +impl AddAssign for StoredU64 { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for StoredU64 { fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { diff --git a/crates/brk_core/src/structs/stored_u8.rs b/crates/brk_core/src/structs/stored_u8.rs index 8597589c3..0d36823aa 100644 --- a/crates/brk_core/src/structs/stored_u8.rs +++ b/crates/brk_core/src/structs/stored_u8.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; @@ -66,6 +66,12 @@ impl Add for StoredU8 { } } +impl AddAssign for StoredU8 { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for StoredU8 { fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { diff --git a/crates/brk_core/src/structs/stored_usize.rs b/crates/brk_core/src/structs/stored_usize.rs index baef5427e..18bd22749 100644 --- a/crates/brk_core/src/structs/stored_usize.rs +++ b/crates/brk_core/src/structs/stored_usize.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use derive_deref::{Deref, DerefMut}; use serde::Serialize; @@ -71,6 +71,12 @@ impl Add for StoredUsize { } } +impl AddAssign for StoredUsize { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for StoredUsize { fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { diff --git a/crates/brk_core/src/structs/timestamp.rs b/crates/brk_core/src/structs/timestamp.rs index e74b90e69..ea104574f 100644 --- a/crates/brk_core/src/structs/timestamp.rs +++ b/crates/brk_core/src/structs/timestamp.rs @@ -1,6 +1,6 @@ use std::{ cmp::Ordering, - ops::{Add, Div}, + ops::{Add, AddAssign, Div}, }; use derive_deref::Deref; @@ -142,6 +142,12 @@ impl Add for Timestamp { } } +impl AddAssign for Timestamp { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl From for Timestamp { fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { diff --git a/crates/brk_core/src/structs/version.rs b/crates/brk_core/src/structs/version.rs index dc740367c..e05109b98 100644 --- a/crates/brk_core/src/structs/version.rs +++ b/crates/brk_core/src/structs/version.rs @@ -65,6 +65,12 @@ impl Version { } } +impl From for u64 { + fn from(value: Version) -> u64 { + value.0 + } +} + impl From for Version { fn from(value: u64) -> Self { Self(value) diff --git a/crates/brk_core/src/structs/weekindex.rs b/crates/brk_core/src/structs/weekindex.rs index 811ec4feb..86c4dca8b 100644 --- a/crates/brk_core/src/structs/weekindex.rs +++ b/crates/brk_core/src/structs/weekindex.rs @@ -31,6 +31,12 @@ impl From for WeekIndex { } } +impl From for u16 { + fn from(value: WeekIndex) -> Self { + value.0 + } +} + impl From for WeekIndex { fn from(value: usize) -> Self { Self(value as u16) @@ -68,7 +74,6 @@ impl From for WeekIndex { let d = jiff::civil::Date::new(year, 6, 6).unwrap(); let i = d.iso_week_date(); let w = i.weeks_in_year(); - // dbg!(d, w); week += w as u16; year += 1; } diff --git a/crates/brk_core/src/structs/weight.rs b/crates/brk_core/src/structs/weight.rs index 5c56ceb6f..10b8ed8ad 100644 --- a/crates/brk_core/src/structs/weight.rs +++ b/crates/brk_core/src/structs/weight.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; @@ -58,6 +58,12 @@ impl Add for Weight { } } +impl AddAssign for Weight { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs + } +} + impl Div for Weight { type Output = Self; fn div(self, rhs: usize) -> Self::Output { diff --git a/crates/brk_core/src/traits/from_coarser.rs b/crates/brk_core/src/traits/from_coarser.rs new file mode 100644 index 000000000..70128db6d --- /dev/null +++ b/crates/brk_core/src/traits/from_coarser.rs @@ -0,0 +1,12 @@ +use std::ops::RangeInclusive; + +pub trait FromCoarserIndex { + fn min_from(coarser: T) -> usize; + fn max_from(coarser: T) -> usize; + fn inclusive_range_from(coarser: T) -> RangeInclusive + where + T: Clone, + { + Self::min_from(coarser.clone())..=Self::max_from(coarser) + } +} diff --git a/crates/brk_core/src/traits/mod.rs b/crates/brk_core/src/traits/mod.rs index ca46c3328..8e724b8e7 100644 --- a/crates/brk_core/src/traits/mod.rs +++ b/crates/brk_core/src/traits/mod.rs @@ -1,3 +1,5 @@ +mod from_coarser; mod printable; +pub use from_coarser::*; pub use printable::*; diff --git a/crates/brk_core/src/utils/rlimit.rs b/crates/brk_core/src/utils/rlimit.rs index 162a52574..a84b8a2a6 100644 --- a/crates/brk_core/src/utils/rlimit.rs +++ b/crates/brk_core/src/utils/rlimit.rs @@ -7,7 +7,7 @@ pub fn setrlimit() -> io::Result<()> { rlimit::setrlimit( Resource::NOFILE, - no_file_limit.0.max(210_000), + no_file_limit.0.max(250_000), no_file_limit.1, )?; diff --git a/crates/brk_interface/src/index.rs b/crates/brk_interface/src/index.rs index f09dfe8f3..4eaf5bb7e 100644 --- a/crates/brk_interface/src/index.rs +++ b/crates/brk_interface/src/index.rs @@ -4,7 +4,8 @@ use brk_core::{ DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, - P2WSHAddressIndex, Printable, QuarterIndex, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex, + P2WSHAddressIndex, Printable, QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex, + WeekIndex, YearIndex, }; use color_eyre::eyre::eyre; use schemars::JsonSchema; @@ -52,6 +53,8 @@ pub enum Index { P2WSHAddressIndex, #[schemars(description = "Quarter index")] QuarterIndex, + #[schemars(description = "Semester index")] + SemesterIndex, #[schemars(description = "Transaction index")] TxIndex, #[schemars(description = "Unknown output index")] @@ -63,7 +66,7 @@ pub enum Index { } impl Index { - pub fn all() -> [Self; 24] { + pub fn all() -> [Self; 25] { [ Self::DateIndex, Self::DecadeIndex, @@ -85,6 +88,7 @@ impl Index { Self::P2WPKHAddressIndex, Self::P2WSHAddressIndex, Self::QuarterIndex, + Self::SemesterIndex, Self::TxIndex, Self::UnknownOutputIndex, Self::WeekIndex, @@ -114,6 +118,7 @@ impl Index { Self::P2WPKHAddressIndex => P2WPKHAddressIndex::to_possible_strings(), Self::P2WSHAddressIndex => P2WSHAddressIndex::to_possible_strings(), Self::QuarterIndex => QuarterIndex::to_possible_strings(), + Self::SemesterIndex => SemesterIndex::to_possible_strings(), Self::TxIndex => TxIndex::to_possible_strings(), Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(), Self::WeekIndex => WeekIndex::to_possible_strings(), @@ -174,7 +179,7 @@ impl TryFrom<&str> for Index { Self::P2WSHAddressIndex } v if (Self::QuarterIndex).possible_values().contains(&v) => Self::QuarterIndex, - v if (Self::QuarterIndex).possible_values().contains(&v) => Self::QuarterIndex, + v if (Self::SemesterIndex).possible_values().contains(&v) => Self::SemesterIndex, v if (Self::TxIndex).possible_values().contains(&v) => Self::TxIndex, v if (Self::WeekIndex).possible_values().contains(&v) => Self::WeekIndex, v if (Self::YearIndex).possible_values().contains(&v) => Self::YearIndex, diff --git a/crates/brk_interface/src/lib.rs b/crates/brk_interface/src/lib.rs index 915309dad..e9bf3df43 100644 --- a/crates/brk_interface/src/lib.rs +++ b/crates/brk_interface/src/lib.rs @@ -6,9 +6,9 @@ use std::collections::BTreeMap; use brk_computer::Computer; -use brk_core::Result; +use brk_core::{Height, Result}; use brk_indexer::Indexer; -use brk_vec::AnyCollectableVec; +use brk_vec::{AnyCollectableVec, AnyIndexedVec}; use tabled::settings::Style; mod deser; @@ -46,6 +46,10 @@ impl<'a> Interface<'a> { } } + pub fn get_height(&self) -> Height { + self._indexer.vecs.height_to_blockhash.height() + } + pub fn search(&self, params: &Params) -> Vec<(String, &&dyn AnyCollectableVec)> { let tuples = params .ids diff --git a/crates/brk_server/Cargo.toml b/crates/brk_server/Cargo.toml index 1e1cc3643..14789f38b 100644 --- a/crates/brk_server/Cargo.toml +++ b/crates/brk_server/Cargo.toml @@ -31,7 +31,7 @@ serde = { workspace = true } tokio = { workspace = true } tower-http = { version = "0.6.6", features = ["compression-full", "trace"] } tracing = "0.1.41" -zip = "4.2.0" +zip = "4.3.0" [package.metadata.cargo-machete] ignored = ["clap"] diff --git a/crates/brk_server/src/api/interface/mod.rs b/crates/brk_server/src/api/interface/mod.rs index 0b1b276b5..f6e18b74d 100644 --- a/crates/brk_server/src/api/interface/mod.rs +++ b/crates/brk_server/src/api/interface/mod.rs @@ -48,6 +48,8 @@ fn req_to_response_res( let to = params.to(); let format = params.format(); + // TODO: From and to should be capped here + let weight = vecs .iter() .map(|(_, v)| v.range_weight(from, to)) @@ -57,7 +59,8 @@ fn req_to_response_res( return Err(eyre!("Request is too heavy, max weight is {MAX_WEIGHT}")); } - let etag = vecs.first().unwrap().1.etag(to); + // TODO: height should be from vec, but good enough for now + let etag = vecs.first().unwrap().1.etag(interface.get_height(), to); if headers .get_if_none_match() diff --git a/crates/brk_vec/src/traits/any.rs b/crates/brk_vec/src/traits/any.rs index 8e50da293..84c516788 100644 --- a/crates/brk_vec/src/traits/any.rs +++ b/crates/brk_vec/src/traits/any.rs @@ -1,4 +1,4 @@ -use brk_core::Version; +use brk_core::{Height, Version}; use super::{BoxedVecIterator, StoredIndex, StoredType}; @@ -20,10 +20,10 @@ pub trait AnyVec: Send + Sync { } fn index_type_to_string(&self) -> &'static str; fn value_type_to_size_of(&self) -> usize; - fn etag(&self, to: Option) -> String { + fn etag(&self, height: Height, to: Option) -> String { let len = self.len(); format!( - "{}-{:?}", + "{}-{}-{}", to.map_or(len, |to| { if to.is_negative() { len.checked_sub(to.unsigned_abs() as usize) @@ -32,7 +32,8 @@ pub trait AnyVec: Send + Sync { to as usize } }), - self.version() + u64::from(self.version()), + u32::from(height), ) } diff --git a/crates/brk_vec/src/traits/generic.rs b/crates/brk_vec/src/traits/generic.rs index 198b4df98..9f51c7745 100644 --- a/crates/brk_vec/src/traits/generic.rs +++ b/crates/brk_vec/src/traits/generic.rs @@ -122,13 +122,14 @@ where fn file_write_all(&mut self, file: &mut File, buf: &[u8]) -> Result<()> { file.write_all(buf)?; + // file.flush()?; + // file.sync_data()?; self.update_mmap(file) } fn file_truncate_and_write_all(&mut self, file: &mut File, len: u64, buf: &[u8]) -> Result<()> { Self::file_set_len_(file, len)?; - file.write_all(buf)?; - self.update_mmap(file) + self.file_write_all(file, buf) } fn reset(&mut self) -> Result<()>; diff --git a/crates/brk_vec/src/variants/computed.rs b/crates/brk_vec/src/variants/computed.rs index 3b876efb1..53cc45ff2 100644 --- a/crates/brk_vec/src/variants/computed.rs +++ b/crates/brk_vec/src/variants/computed.rs @@ -92,7 +92,7 @@ where S3T: StoredType, { pub fn forced_import_or_init_from_1( - mode: Computation, + computation: Computation, path: &Path, name: &str, version: Version, @@ -100,7 +100,7 @@ where source: BoxedAnyIterableVec, compute: ComputeFrom1, ) -> Result { - Ok(match mode { + Ok(match computation { Computation::Eager => Self::Eager { vec: EagerVec::forced_import(path, name, version, format)?, deps: Dependencies::From1(source, compute), @@ -114,7 +114,7 @@ where #[allow(clippy::too_many_arguments)] pub fn forced_import_or_init_from_2( - mode: Computation, + computation: Computation, path: &Path, name: &str, version: Version, @@ -123,7 +123,7 @@ where source2: BoxedAnyIterableVec, compute: ComputeFrom2, ) -> Result { - Ok(match mode { + Ok(match computation { Computation::Eager => Self::Eager { vec: EagerVec::forced_import(path, name, version, format)?, deps: Dependencies::From2((source1, source2), compute), @@ -137,7 +137,7 @@ where #[allow(clippy::too_many_arguments)] pub fn forced_import_or_init_from_3( - mode: Computation, + computation: Computation, path: &Path, name: &str, version: Version, @@ -147,7 +147,7 @@ where source3: BoxedAnyIterableVec, compute: ComputeFrom3, ) -> Result { - Ok(match mode { + Ok(match computation { Computation::Eager => Self::Eager { vec: EagerVec::forced_import(path, name, version, format)?, deps: Dependencies::From3((source1, source2, source3), compute), diff --git a/crates/brk_vec/src/variants/lazy1.rs b/crates/brk_vec/src/variants/lazy1.rs index f14fa9d89..e69c26b71 100644 --- a/crates/brk_vec/src/variants/lazy1.rs +++ b/crates/brk_vec/src/variants/lazy1.rs @@ -35,10 +35,6 @@ where source: BoxedAnyIterableVec, compute: ComputeFrom1, ) -> Self { - if source.index_type_to_string() != I::to_string() { - panic!("Should have same index"); - } - Self { name: name.to_string(), version, diff --git a/websites/default/packages/lightweight-charts/wrapper.js b/websites/default/packages/lightweight-charts/wrapper.js index 1246df2a7..fd9e5ad79 100644 --- a/websites/default/packages/lightweight-charts/wrapper.js +++ b/websites/default/packages/lightweight-charts/wrapper.js @@ -184,11 +184,13 @@ function createChartElement({ ? 1 : index === /** @satisfies {QuarterIndex} */ (19) ? 2 - : index === /** @satisfies {YearIndex} */ (23) - ? 6 - : index === /** @satisfies {DecadeIndex} */ (1) - ? 60 - : 0.5; + : index === /** @satisfies {SemesterIndex} */ (20) + ? 3 + : index === /** @satisfies {YearIndex} */ (24) + ? 6 + : index === /** @satisfies {DecadeIndex} */ (1) + ? 60 + : 0.5; ichart.applyOptions({ timeScale: { @@ -474,7 +476,8 @@ function createChartElement({ timeScaleSetCallback?.(() => { if ( index === /** @satisfies {QuarterIndex} */ (19) || - index === /** @satisfies {YearIndex} */ (23) || + index === /** @satisfies {SemesterIndex} */ (20) || + index === /** @satisfies {YearIndex} */ (24) || index === /** @satisfies {DecadeIndex} */ (1) ) { ichart.timeScale().setVisibleLogicalRange({ diff --git a/websites/default/scripts/chart.js b/websites/default/scripts/chart.js index e2d381f47..afe0b2682 100644 --- a/websites/default/scripts/chart.js +++ b/websites/default/scripts/chart.js @@ -7,7 +7,7 @@ const LINE = "line"; const CANDLE = "candle"; /** - * @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "year" | "decade" } SerializedChartableIndex + * @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "semester" | "year" | "decade" } SerializedChartableIndex */ /** @@ -205,14 +205,17 @@ export function init({ break; } default: { - if (index === /** @satisfies {WeekIndex} */ (22)) { + if (index === /** @satisfies {WeekIndex} */ (23)) { date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7)); } else if (index === /** @satisfies {MonthIndex} */ (7)) { date.setUTCDate(1); } else if (index === /** @satisfies {QuarterIndex} */ (19)) { const month = date.getUTCMonth(); date.setUTCMonth(month - (month % 3), 1); - } else if (index === /** @satisfies {YearIndex} */ (23)) { + } else if (index === /** @satisfies {SemesterIndex} */ (20)) { + const month = date.getUTCMonth(); + date.setUTCMonth(month - (month % 6), 1); + } else if (index === /** @satisfies {YearIndex} */ (24)) { date.setUTCMonth(0, 1); } else if (index === /** @satisfies {DecadeIndex} */ (1)) { date.setUTCFullYear( @@ -465,6 +468,7 @@ function createIndexSelector({ option, vecIdToIndexes, signals, utils }) { "d.epoch", "month", "quarter", + "semester", "year", // "halving epoch", "decade", diff --git a/websites/default/scripts/main.js b/websites/default/scripts/main.js index c8638ff71..67208e6d8 100644 --- a/websites/default/scripts/main.js +++ b/websites/default/scripts/main.js @@ -6,7 +6,7 @@ * @import * as _ from "../packages/ufuzzy/v1.0.18/types" * @import { SerializedChartableIndex } from "./chart"; * @import { Signal, Signals, Accessor } from "../packages/solid-signals/wrapper"; - * @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes" + * @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, SemesterIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes" */ /** @@ -1164,13 +1164,15 @@ function createUtils() { return "p2wshaddressindex"; case /** @satisfies {QuarterIndex} */ (19): return "quarterindex"; - case /** @satisfies {TxIndex} */ (20): + case /** @satisfies {SemesterIndex} */ (20): + return "semesterindex"; + case /** @satisfies {TxIndex} */ (21): return "txindex"; - case /** @satisfies {UnknownOutputIndex} */ (21): + case /** @satisfies {UnknownOutputIndex} */ (22): return "unknownoutputindex"; - case /** @satisfies {WeekIndex} */ (22): + case /** @satisfies {WeekIndex} */ (23): return "weekindex"; - case /** @satisfies {YearIndex} */ (23): + case /** @satisfies {YearIndex} */ (24): return "yearindex"; } }, @@ -1196,9 +1198,11 @@ function createUtils() { return "month"; case /** @satisfies {QuarterIndex} */ (19): return "quarter"; - case /** @satisfies {WeekIndex} */ (22): + case /** @satisfies {SemesterIndex} */ (20): + return "semester"; + case /** @satisfies {WeekIndex} */ (23): return "week"; - case /** @satisfies {YearIndex} */ (23): + case /** @satisfies {YearIndex} */ (24): return "year"; default: return null; @@ -1215,15 +1219,17 @@ function createUtils() { case "date": return /** @satisfies {DateIndex} */ (0); case "week": - return /** @satisfies {WeekIndex} */ (22); + return /** @satisfies {WeekIndex} */ (23); case "d.epoch": return /** @satisfies {DifficultyEpoch} */ (2); case "month": return /** @satisfies {MonthIndex} */ (7); case "quarter": return /** @satisfies {QuarterIndex} */ (19); + case "semester": + return /** @satisfies {SemesterIndex} */ (20); case "year": - return /** @satisfies {YearIndex} */ (23); + return /** @satisfies {YearIndex} */ (24); case "decade": return /** @satisfies {DecadeIndex} */ (1); default: diff --git a/websites/default/scripts/table.js b/websites/default/scripts/table.js index cc5fcf621..fba8e74e5 100644 --- a/websites/default/scripts/table.js +++ b/websites/default/scripts/table.js @@ -406,6 +406,7 @@ function createSerializedIndexes() { /** @satisfies {VecId} */ ("inputindex"), /** @satisfies {VecId} */ ("monthindex"), /** @satisfies {VecId} */ ("opreturnindex"), + /** @satisfies {VecId} */ ("semesterindex"), /** @satisfies {VecId} */ ("outputindex"), /** @satisfies {VecId} */ ("p2aaddressindex"), /** @satisfies {VecId} */ ("p2msoutputindex"), @@ -437,21 +438,23 @@ function serializedIndexToIndex(serializedIndex) { case "dateindex": return /** @satisfies {DateIndex} */ (0); case "weekindex": - return /** @satisfies {WeekIndex} */ (22); + return /** @satisfies {WeekIndex} */ (23); case "difficultyepoch": return /** @satisfies {DifficultyEpoch} */ (2); case "monthindex": return /** @satisfies {MonthIndex} */ (7); case "quarterindex": return /** @satisfies {QuarterIndex} */ (19); + case "semesterindex": + return /** @satisfies {SemesterIndex} */ (20); case "yearindex": - return /** @satisfies {YearIndex} */ (23); + return /** @satisfies {YearIndex} */ (24); case "decadeindex": return /** @satisfies {DecadeIndex} */ (1); case "halvingepoch": return /** @satisfies {HalvingEpoch} */ (4); case "txindex": - return /** @satisfies {TxIndex} */ (20); + return /** @satisfies {TxIndex} */ (21); case "inputindex": return /** @satisfies {InputIndex} */ (6); case "outputindex": @@ -479,7 +482,7 @@ function serializedIndexToIndex(serializedIndex) { case "emptyoutputindex": return /** @satisfies {EmptyOutputIndex} */ (3); case "unknownoutputindex": - return /** @satisfies {UnknownOutputIndex} */ (21); + return /** @satisfies {UnknownOutputIndex} */ (22); } }