global: adding semester + making coarser intervals computed instead of eager

This commit is contained in:
nym21
2025-07-10 17:44:19 +02:00
parent a66f4ad4bd
commit c229e218f6
65 changed files with 2490 additions and 1003 deletions
Generated
+24 -23
View File
@@ -1150,21 +1150,11 @@ checksum = "6236364b88b9b6d0bc181ba374cf1ab55ba3ef97a1cb6f8cddad48a273767fb5"
[[package]] [[package]]
name = "bzip2" name = "bzip2"
version = "0.5.2" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47" checksum = "bea8dcd42434048e4f7a304411d9273a411f647446c1234a65ce0554923f4cff"
dependencies = [ dependencies = [
"bzip2-sys", "libbz2-rs-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",
] ]
[[package]] [[package]]
@@ -1237,18 +1227,18 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.40" version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
] ]
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.40" version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@@ -1258,9 +1248,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.40" version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@@ -1912,11 +1902,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"r-efi", "r-efi",
"wasi 0.14.2+wasi-0.2.4", "wasi 0.14.2+wasi-0.2.4",
"wasm-bindgen",
] ]
[[package]] [[package]]
@@ -2316,6 +2304,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libbz2-rs-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "775bf80d5878ab7c2b1080b5351a48b2f737d9f6f8b383574eebcc22be0dfccb"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.174" version = "0.2.174"
@@ -3318,6 +3312,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppmd-rust"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c834641d8ad1b348c9ee86dec3b9840d805acd5f24daa5f90c788951a52ff59b"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.21" version = "0.2.21"
@@ -4996,9 +4996,9 @@ dependencies = [
[[package]] [[package]]
name = "zip" name = "zip"
version = "4.2.0" version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ab361742de920c5535880f89bbd611ee62002bf11341d16a5f057bb8ba6899" checksum = "9aed4ac33e8eb078c89e6cbb1d5c4c7703ec6d299fc3e7c3695af8f8b423468b"
dependencies = [ dependencies = [
"aes", "aes",
"arbitrary", "arbitrary",
@@ -5013,6 +5013,7 @@ dependencies = [
"liblzma", "liblzma",
"memchr", "memchr",
"pbkdf2", "pbkdf2",
"ppmd-rust",
"sha1", "sha1",
"time", "time",
"zeroize", "zeroize",
+2 -2
View File
@@ -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_store = { version = "0.0.76", path = "crates/brk_store" }
brk_vec = { version = "0.0.76", path = "crates/brk_vec" } brk_vec = { version = "0.0.76", path = "crates/brk_vec" }
byteview = "=0.6.1" byteview = "=0.6.1"
clap = { version = "4.5.40", features = ["string"] } clap = { version = "4.5.41", features = ["string"] }
clap_derive = "4.5.40" clap_derive = "4.5.41"
color-eyre = "0.6.5" color-eyre = "0.6.5"
derive_deref = "1.1.1" derive_deref = "1.1.1"
fjall = "2.11.1" fjall = "2.11.1"
+7 -1
View File
@@ -17,14 +17,19 @@
- add address counts relative to all datasets - add address counts relative to all datasets
- make decade, quarter, year datasets `computed` instead of `eager` - make decade, quarter, year datasets `computed` instead of `eager`
- add 6 months (semester) interval datasets to builder - add 6 months (semester) interval datasets to builder
- some datasets in `indexes` can probably be removed
- add revived/sent supply datasets - add revived/sent supply datasets
- add `in-sats` version of all price datasets (average and co) - add `in-sats` version of all price datasets (average and co)
- add `p2pk` group (sum of `p2pk33` and `p2pk65`) - 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 more date ranges (3-6 months and more)
- add puell multiple dataset - add puell multiple dataset
- add pi cycle 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 - 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: - add all possible charts from:
- https://mainnet.observer - https://mainnet.observer
- https://glassnode.com - https://glassnode.com
@@ -73,6 +78,7 @@
- remove `sum` series when it's a duplicate of the `base` (in subsidy for example) - remove `sum` series when it's a duplicate of the `base` (in subsidy for example)
- selected unit sometimes changes when going back end forth - selected unit sometimes changes when going back end forth
- add support for custom charts - 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) - price scale format depends on unit, hide digits for sats for example (if/when possible)
- table - table
- pagination - pagination
+22 -22
View File
@@ -8,9 +8,11 @@ use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format}; use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format};
use crate::vecs::grouped::Source;
use super::{ use super::{
Indexes, Indexes,
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes, indexes,
}; };
@@ -34,7 +36,7 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
version: Version, version: Version,
_computation: Computation, computation: Computation,
format: Format, format: Format,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
@@ -47,18 +49,20 @@ impl Vecs {
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import( timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
path, path,
"timestamp", "timestamp",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_first(), computation,
EagerVecBuilderOptions::default().add_first(),
)?, )?,
indexes_to_block_interval: ComputedVecsFromHeight::forced_import( indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
path, path,
"block_interval", "block_interval",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_percentiles() .add_percentiles()
.add_minmax() .add_minmax()
.add_average(), .add_average(),
@@ -66,32 +70,29 @@ impl Vecs {
indexes_to_block_count: ComputedVecsFromHeight::forced_import( indexes_to_block_count: ComputedVecsFromHeight::forced_import(
path, path,
"block_count", "block_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_block_weight: ComputedVecsFromHeight::forced_import( indexes_to_block_weight: ComputedVecsFromHeight::forced_import(
path, path,
"block_weight", "block_weight",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_block_size: ComputedVecsFromHeight::forced_import( indexes_to_block_size: ComputedVecsFromHeight::forced_import(
path, path,
"block_size", "block_size",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
height_to_vbytes: EagerVec::forced_import( height_to_vbytes: EagerVec::forced_import(
path, path,
@@ -102,12 +103,11 @@ impl Vecs {
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import( indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
path, path,
"block_vbytes", "block_vbytes",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
difficultyepoch_to_timestamp: EagerVec::forced_import( difficultyepoch_to_timestamp: EagerVec::forced_import(
path, path,
+68 -55
View File
@@ -7,13 +7,13 @@ use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
use crate::vecs::{ use crate::vecs::{
fetched, fetched,
grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight}, grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, Source},
stateful, transactions, stateful, transactions,
}; };
use super::{ use super::{
Indexes, Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes, indexes,
}; };
@@ -51,7 +51,7 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
version: Version, version: Version,
_computation: Computation, computation: Computation,
format: Format, format: Format,
fetched: Option<&fetched::Vecs>, fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
@@ -61,194 +61,207 @@ impl Vecs {
indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import( indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import(
path, path,
"coinblocks_created", "coinblocks_created",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_coinblocks_stored: ComputedVecsFromHeight::forced_import( indexes_to_coinblocks_stored: ComputedVecsFromHeight::forced_import(
path, path,
"coinblocks_stored", "coinblocks_stored",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_liveliness: ComputedVecsFromHeight::forced_import( indexes_to_liveliness: ComputedVecsFromHeight::forced_import(
path, path,
"liveliness", "liveliness",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_vaultedness: ComputedVecsFromHeight::forced_import( indexes_to_vaultedness: ComputedVecsFromHeight::forced_import(
path, path,
"vaultedness", "vaultedness",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight::forced_import( indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight::forced_import(
path, path,
"activity_to_vaultedness_ratio", "activity_to_vaultedness_ratio",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_vaulted_supply: ComputedValueVecsFromHeight::forced_import( indexes_to_vaulted_supply: ComputedValueVecsFromHeight::forced_import(
path, path,
"vaulted_supply", "vaulted_supply",
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
)?, )?,
indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import( indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import(
path, path,
"active_supply", "active_supply",
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
)?, )?,
indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import( indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import(
path, path,
"thermo_cap", "thermo_cap",
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_investor_cap: ComputedVecsFromHeight::forced_import( indexes_to_investor_cap: ComputedVecsFromHeight::forced_import(
path, path,
"investor_cap", "investor_cap",
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_vaulted_cap: ComputedVecsFromHeight::forced_import( indexes_to_vaulted_cap: ComputedVecsFromHeight::forced_import(
path, path,
"vaulted_cap", "vaulted_cap",
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_active_cap: ComputedVecsFromHeight::forced_import( indexes_to_active_cap: ComputedVecsFromHeight::forced_import(
path, path,
"active_cap", "active_cap",
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_vaulted_price: ComputedVecsFromHeight::forced_import( indexes_to_vaulted_price: ComputedVecsFromHeight::forced_import(
path, path,
"vaulted_price", "vaulted_price",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import( indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path, path,
"vaulted_price", "vaulted_price",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
)?, )?,
indexes_to_active_price: ComputedVecsFromHeight::forced_import( indexes_to_active_price: ComputedVecsFromHeight::forced_import(
path, path,
"active_price", "active_price",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import( indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path, path,
"active_price", "active_price",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
)?, )?,
indexes_to_true_market_mean: ComputedVecsFromHeight::forced_import( indexes_to_true_market_mean: ComputedVecsFromHeight::forced_import(
path, path,
"true_market_mean", "true_market_mean",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_true_market_mean_ratio: ComputedRatioVecsFromDateIndex::forced_import( indexes_to_true_market_mean_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path, path,
"true_market_mean", "true_market_mean",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
)?, )?,
indexes_to_cointime_value_destroyed: ComputedVecsFromHeight::forced_import( indexes_to_cointime_value_destroyed: ComputedVecsFromHeight::forced_import(
path, path,
"cointime_value_destroyed", "cointime_value_destroyed",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_cointime_value_created: ComputedVecsFromHeight::forced_import( indexes_to_cointime_value_created: ComputedVecsFromHeight::forced_import(
path, path,
"cointime_value_created", "cointime_value_created",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_cointime_value_stored: ComputedVecsFromHeight::forced_import( indexes_to_cointime_value_stored: ComputedVecsFromHeight::forced_import(
path, path,
"cointime_value_stored", "cointime_value_stored",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_cointime_price: ComputedVecsFromHeight::forced_import( indexes_to_cointime_price: ComputedVecsFromHeight::forced_import(
path, path,
"cointime_price", "cointime_price",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_cointime_cap: ComputedVecsFromHeight::forced_import( indexes_to_cointime_cap: ComputedVecsFromHeight::forced_import(
path, path,
"cointime_cap", "cointime_cap",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import( indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path, path,
"cointime_price", "cointime_price",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
)?, )?,
}) })
} }
+16 -10
View File
@@ -5,9 +5,11 @@ use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyVec, Computation, Format}; use brk_vec::{AnyCollectableVec, AnyVec, Computation, Format};
use crate::vecs::grouped::Source;
use super::{ use super::{
Indexes, Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes, indexes,
}; };
@@ -25,41 +27,45 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
version: Version, version: Version,
_computation: Computation, computation: Computation,
format: Format, format: Format,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
constant_0: ComputedVecsFromHeight::forced_import( constant_0: ComputedVecsFromHeight::forced_import(
path, path,
"constant_0", "constant_0",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
constant_1: ComputedVecsFromHeight::forced_import( constant_1: ComputedVecsFromHeight::forced_import(
path, path,
"constant_1", "constant_1",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
constant_50: ComputedVecsFromHeight::forced_import( constant_50: ComputedVecsFromHeight::forced_import(
path, path,
"constant_50", "constant_50",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
constant_100: ComputedVecsFromHeight::forced_import( constant_100: ComputedVecsFromHeight::forced_import(
path, path,
"constant_100", "constant_100",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
}) })
} }
+109 -29
View File
@@ -2,18 +2,19 @@ use std::path::Path;
use brk_core::{ use brk_core::{
Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex, 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_exit::Exit;
use brk_fetcher::Fetcher; use brk_fetcher::Fetcher;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format, StoredIndex}; use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format, StoredIndex};
use crate::vecs::grouped::Source;
use super::{ use super::{
Indexes, Indexes,
grouped::{ grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, EagerVecBuilderOptions},
ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, StorableVecGeneatorOptions,
},
indexes, indexes,
}; };
@@ -57,6 +58,8 @@ pub struct Vecs {
pub monthindex_to_ohlc_in_sats: EagerVec<MonthIndex, OHLCSats>, pub monthindex_to_ohlc_in_sats: EagerVec<MonthIndex, OHLCSats>,
pub quarterindex_to_ohlc: EagerVec<QuarterIndex, OHLCDollars>, pub quarterindex_to_ohlc: EagerVec<QuarterIndex, OHLCDollars>,
pub quarterindex_to_ohlc_in_sats: EagerVec<QuarterIndex, OHLCSats>, pub quarterindex_to_ohlc_in_sats: EagerVec<QuarterIndex, OHLCSats>,
pub semesterindex_to_ohlc: EagerVec<SemesterIndex, OHLCDollars>,
pub semesterindex_to_ohlc_in_sats: EagerVec<SemesterIndex, OHLCSats>,
pub yearindex_to_ohlc: EagerVec<YearIndex, OHLCDollars>, pub yearindex_to_ohlc: EagerVec<YearIndex, OHLCDollars>,
pub yearindex_to_ohlc_in_sats: EagerVec<YearIndex, OHLCSats>, pub yearindex_to_ohlc_in_sats: EagerVec<YearIndex, OHLCSats>,
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>, // pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
@@ -72,7 +75,7 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
version: Version, version: Version,
_computation: Computation, computation: Computation,
format: Format, format: Format,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let mut fetched_path = path.to_owned(); let mut fetched_path = path.to_owned();
@@ -167,122 +170,130 @@ impl Vecs {
timeindexes_to_open: ComputedVecsFromDateIndex::forced_import( timeindexes_to_open: ComputedVecsFromDateIndex::forced_import(
path, path,
"open", "open",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_first(), computation,
EagerVecBuilderOptions::default().add_first(),
)?, )?,
timeindexes_to_high: ComputedVecsFromDateIndex::forced_import( timeindexes_to_high: ComputedVecsFromDateIndex::forced_import(
path, path,
"high", "high",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_max(), computation,
EagerVecBuilderOptions::default().add_max(),
)?, )?,
timeindexes_to_low: ComputedVecsFromDateIndex::forced_import( timeindexes_to_low: ComputedVecsFromDateIndex::forced_import(
path, path,
"low", "low",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_min(), computation,
EagerVecBuilderOptions::default().add_min(),
)?, )?,
timeindexes_to_close: ComputedVecsFromDateIndex::forced_import( timeindexes_to_close: ComputedVecsFromDateIndex::forced_import(
path, path,
"close", "close",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import( timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import(
path, path,
"open_in_sats", "open_in_sats",
true, Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_first(), computation,
EagerVecBuilderOptions::default().add_first(),
)?, )?,
timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import( timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import(
path, path,
"high_in_sats", "high_in_sats",
true, Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_max(), computation,
EagerVecBuilderOptions::default().add_max(),
)?, )?,
timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import( timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import(
path, path,
"low_in_sats", "low_in_sats",
true, Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_min(), computation,
EagerVecBuilderOptions::default().add_min(),
)?, )?,
timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import( timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import(
path, path,
"close_in_sats", "close_in_sats",
true, Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
path, path,
"open", "open",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_first(), EagerVecBuilderOptions::default().add_first(),
)?, )?,
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
path, path,
"high", "high",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_max(), EagerVecBuilderOptions::default().add_max(),
)?, )?,
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
path, path,
"low", "low",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_min(), EagerVecBuilderOptions::default().add_min(),
)?, )?,
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
path, path,
"close", "close",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), EagerVecBuilderOptions::default().add_last(),
)?, )?,
chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import(
path, path,
"open_in_sats", "open_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_first(), EagerVecBuilderOptions::default().add_first(),
)?, )?,
chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import(
path, path,
"high_in_sats", "high_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_max(), EagerVecBuilderOptions::default().add_max(),
)?, )?,
chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import(
path, path,
"low_in_sats", "low_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_min(), EagerVecBuilderOptions::default().add_min(),
)?, )?,
chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import(
path, path,
"close_in_sats", "close_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), EagerVecBuilderOptions::default().add_last(),
)?, )?,
weekindex_to_ohlc: EagerVec::forced_import( weekindex_to_ohlc: EagerVec::forced_import(
path, path,
@@ -332,6 +343,18 @@ impl Vecs {
version + VERSION + VERSION_IN_SATS + Version::ZERO, version + VERSION + VERSION_IN_SATS + Version::ZERO,
format, 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( yearindex_to_ohlc: EagerVec::forced_import(
path, path,
"ohlc", "ohlc",
@@ -693,6 +716,27 @@ impl Vecs {
exit, 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_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_max_iter = self.timeindexes_to_high.yearindex.unwrap_max().iter();
let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter(); let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter();
@@ -1044,6 +1088,40 @@ impl Vecs {
exit, 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 let mut yearindex_first_iter = self
.timeindexes_to_open_in_sats .timeindexes_to_open_in_sats
.yearindex .yearindex
@@ -1133,6 +1211,7 @@ impl Vecs {
&self.difficultyepoch_to_ohlc, &self.difficultyepoch_to_ohlc,
&self.monthindex_to_ohlc, &self.monthindex_to_ohlc,
&self.quarterindex_to_ohlc, &self.quarterindex_to_ohlc,
&self.semesterindex_to_ohlc,
&self.yearindex_to_ohlc, &self.yearindex_to_ohlc,
// &self.halvingepoch_to_ohlc, // &self.halvingepoch_to_ohlc,
&self.decadeindex_to_ohlc, &self.decadeindex_to_ohlc,
@@ -1142,6 +1221,7 @@ impl Vecs {
&self.difficultyepoch_to_ohlc_in_sats, &self.difficultyepoch_to_ohlc_in_sats,
&self.monthindex_to_ohlc_in_sats, &self.monthindex_to_ohlc_in_sats,
&self.quarterindex_to_ohlc_in_sats, &self.quarterindex_to_ohlc_in_sats,
&self.semesterindex_to_ohlc_in_sats,
&self.yearindex_to_ohlc_in_sats, &self.yearindex_to_ohlc_in_sats,
// &self.halvingepoch_to_ohlc_in_sats, // &self.halvingepoch_to_ohlc_in_sats,
&self.decadeindex_to_ohlc_in_sats, &self.decadeindex_to_ohlc_in_sats,
@@ -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<I, T, S1I>
where
I: StoredIndex,
T: ComputedType,
{
pub first: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
pub average: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
pub sum: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
pub max: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
pub min: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
pub last: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
pub cumulative: Option<Box<ComputedVecFrom1<I, T, S1I, T>>>,
}
const VERSION: Version = Version::ZERO;
impl<I, T, S1I> ComputedVecBuilder<I, T, S1I>
where
I: StoredIndex,
T: ComputedType + 'static,
S1I: StoredIndex + 'static + FromCoarserIndex<I>,
{
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
version: Version,
format: Format,
computation: Computation,
source: Option<BoxedAnyIterableVec<S1I, T>>,
source_extra: &EagerVecBuilder<S1I, T>,
options: ComputedVecBuilderOptions,
) -> color_eyre::Result<Self> {
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::<Vec<_>>();
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::<Vec<_>>();
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<T2>(
&mut self,
max_from: I,
len_source: &impl AnyIterableVec<I, T2>,
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<I, T, S1I, T> {
self.first.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_average(&self) -> &ComputedVecFrom1<I, T, S1I, T> {
self.average.as_ref().unwrap()
}
pub fn unwrap_sum(&self) -> &ComputedVecFrom1<I, T, S1I, T> {
self.sum.as_ref().unwrap()
}
pub fn unwrap_max(&self) -> &ComputedVecFrom1<I, T, S1I, T> {
self.max.as_ref().unwrap()
}
pub fn unwrap_min(&self) -> &ComputedVecFrom1<I, T, S1I, T> {
self.min.as_ref().unwrap()
}
pub fn unwrap_last(&self) -> &ComputedVecFrom1<I, T, S1I, T> {
self.last.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_cumulative(&self) -> &ComputedVecFrom1<I, T, S1I, T> {
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<EagerVecBuilderOptions> 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()
}
}
}
@@ -10,7 +10,7 @@ use crate::utils::get_percentile;
use super::ComputedType; use super::ComputedType;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ComputedVecBuilder<I, T> pub struct EagerVecBuilder<I, T>
where where
I: StoredIndex, I: StoredIndex,
T: ComputedType, T: ComputedType,
@@ -31,7 +31,7 @@ where
const VERSION: Version = Version::ZERO; const VERSION: Version = Version::ZERO;
impl<I, T> ComputedVecBuilder<I, T> impl<I, T> EagerVecBuilder<I, T>
where where
I: StoredIndex, I: StoredIndex,
T: ComputedType, T: ComputedType,
@@ -41,7 +41,7 @@ where
name: &str, name: &str,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let only_one_active = options.is_only_one_active(); let only_one_active = options.is_only_one_active();
@@ -384,7 +384,7 @@ where
pub fn from_aligned<I2>( pub fn from_aligned<I2>(
&mut self, &mut self,
max_from: I, max_from: I,
source: &ComputedVecBuilder<I2, T>, source: &EagerVecBuilder<I2, T>,
first_indexes: &impl AnyIterableVec<I, I2>, first_indexes: &impl AnyIterableVec<I, I2>,
count_indexes: &impl AnyIterableVec<I, StoredUsize>, count_indexes: &impl AnyIterableVec<I, StoredUsize>,
exit: &Exit, exit: &Exit,
@@ -706,7 +706,7 @@ where
} }
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy)]
pub struct StorableVecGeneatorOptions { pub struct EagerVecBuilderOptions {
average: bool, average: bool,
sum: bool, sum: bool,
max: bool, max: bool,
@@ -721,7 +721,55 @@ pub struct StorableVecGeneatorOptions {
cumulative: bool, 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 { pub fn add_first(mut self) -> Self {
self.first = true; self.first = true;
self self
@@ -1,15 +1,18 @@
use std::path::Path; use std::path::Path;
use brk_core::{ 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_exit::Exit;
use brk_indexer::Indexer; 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)] #[derive(Clone)]
pub struct ComputedVecsFromDateIndex<T> pub struct ComputedVecsFromDateIndex<T>
@@ -17,33 +20,35 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub dateindex: Option<EagerVec<DateIndex, T>>, pub dateindex: Option<EagerVec<DateIndex, T>>,
pub dateindex_extra: ComputedVecBuilder<DateIndex, T>, pub dateindex_extra: EagerVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>, pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>, pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>, pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T>, pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>, pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex>,
} }
const VERSION: Version = Version::ZERO; const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromDateIndex<T> impl<T> ComputedVecsFromDateIndex<T>
where where
T: ComputedType, T: ComputedType + 'static,
{ {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<DateIndex, T>,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, computation: Computation,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let dateindex = compute_source.then(|| { let dateindex = source.is_compute().then(|| {
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap() EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap()
}); });
let dateindex_extra = ComputedVecBuilder::forced_import( let dateindex_extra = EagerVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -53,44 +58,71 @@ where
let options = options.remove_percentiles(); let options = options.remove_percentiles();
let dateindex_source = source.vec().or(dateindex.as_ref().map(|v| v.boxed_clone()));
Ok(Self { Ok(Self {
dateindex,
dateindex_extra,
weekindex: ComputedVecBuilder::forced_import( weekindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?, )?,
monthindex: ComputedVecBuilder::forced_import( monthindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?, )?,
quarterindex: ComputedVecBuilder::forced_import( quarterindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, 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( yearindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?, )?,
decadeindex: ComputedVecBuilder::forced_import( decadeindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?, )?,
dateindex,
dateindex_extra,
}) })
} }
@@ -133,65 +165,45 @@ where
if let Some(dateindex) = dateindex { if let Some(dateindex) = dateindex {
self.dateindex_extra self.dateindex_extra
.extend(starting_indexes.dateindex, dateindex, exit)?; .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 { } else {
let dateindex = self.dateindex.as_ref().unwrap(); let dateindex = self.dateindex.as_ref().unwrap();
self.dateindex_extra self.dateindex_extra
.extend(starting_indexes.dateindex, dateindex, exit)?; .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, starting_indexes.quarterindex,
&self.monthindex,
&indexes.quarterindex_to_first_monthindex,
&indexes.quarterindex_to_monthindex_count, &indexes.quarterindex_to_monthindex_count,
exit, 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, starting_indexes.yearindex,
&self.monthindex,
&indexes.yearindex_to_first_monthindex,
&indexes.yearindex_to_monthindex_count, &indexes.yearindex_to_monthindex_count,
exit, exit,
)?; )?;
self.decadeindex.from_aligned( self.decadeindex.compute_if_necessary(
starting_indexes.decadeindex, starting_indexes.decadeindex,
&self.yearindex,
&indexes.decadeindex_to_first_yearindex,
&indexes.decadeindex_to_yearindex_count, &indexes.decadeindex_to_yearindex_count,
exit, exit,
)?; )?;
@@ -208,6 +220,7 @@ where
self.weekindex.vecs(), self.weekindex.vecs(),
self.monthindex.vecs(), self.monthindex.vecs(),
self.quarterindex.vecs(), self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(), self.yearindex.vecs(),
self.decadeindex.vecs(), self.decadeindex.vecs(),
] ]
@@ -1,16 +1,20 @@
use std::path::Path; use std::path::Path;
use brk_core::{ use brk_core::{
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result, Version, DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result,
WeekIndex, YearIndex, SemesterIndex, Version, WeekIndex, YearIndex,
}; };
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; 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)] #[derive(Clone)]
pub struct ComputedVecsFromHeight<T> pub struct ComputedVecsFromHeight<T>
@@ -18,38 +22,39 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub height: Option<EagerVec<Height, T>>, pub height: Option<EagerVec<Height, T>>,
pub height_extra: ComputedVecBuilder<Height, T>, pub height_extra: EagerVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<DateIndex, T>, pub dateindex: EagerVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>, pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>, pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>, pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>, pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex>,
// 6 months pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T>, pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>, // TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>, pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex>,
} }
const VERSION: Version = Version::ZERO; const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromHeight<T> impl<T> ComputedVecsFromHeight<T>
where where
T: ComputedType + Ord + From<f64>, T: ComputedType + Ord + From<f64> + 'static,
f64: From<T>, f64: From<T>,
{ {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<Height, T>,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, computation: Computation,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let height = compute_source.then(|| { let height = source.is_compute().then(|| {
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap() EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap()
}); });
let height_extra = ComputedVecBuilder::forced_import( let height_extra = EagerVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -57,7 +62,7 @@ where
options.copy_self_extra(), options.copy_self_extra(),
)?; )?;
let dateindex = ComputedVecBuilder::forced_import( let dateindex = EagerVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -68,46 +73,71 @@ where
let options = options.remove_percentiles(); let options = options.remove_percentiles();
Ok(Self { Ok(Self {
height,
height_extra,
dateindex,
weekindex: ComputedVecBuilder::forced_import( weekindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
)?, None,
difficultyepoch: ComputedVecBuilder::forced_import( &dateindex,
path, options.into(),
name,
version + VERSION + Version::ZERO,
format,
options,
)?, )?,
monthindex: ComputedVecBuilder::forced_import( monthindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
None,
&dateindex,
options.into(),
)?, )?,
quarterindex: ComputedVecBuilder::forced_import( quarterindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, 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( yearindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, 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)?, // 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, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -189,42 +219,38 @@ where
)?; )?;
} }
self.weekindex.from_aligned( self.weekindex.compute_if_necessary(
starting_indexes.weekindex, starting_indexes.weekindex,
&self.dateindex,
&indexes.weekindex_to_first_dateindex,
&indexes.weekindex_to_dateindex_count, &indexes.weekindex_to_dateindex_count,
exit, exit,
)?; )?;
self.monthindex.from_aligned( self.monthindex.compute_if_necessary(
starting_indexes.monthindex, starting_indexes.monthindex,
&self.dateindex,
&indexes.monthindex_to_first_dateindex,
&indexes.monthindex_to_dateindex_count, &indexes.monthindex_to_dateindex_count,
exit, exit,
)?; )?;
self.quarterindex.from_aligned( self.quarterindex.compute_if_necessary(
starting_indexes.quarterindex, starting_indexes.quarterindex,
&self.monthindex,
&indexes.quarterindex_to_first_monthindex,
&indexes.quarterindex_to_monthindex_count, &indexes.quarterindex_to_monthindex_count,
exit, 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, starting_indexes.yearindex,
&self.monthindex,
&indexes.yearindex_to_first_monthindex,
&indexes.yearindex_to_monthindex_count, &indexes.yearindex_to_monthindex_count,
exit, exit,
)?; )?;
self.decadeindex.from_aligned( self.decadeindex.compute_if_necessary(
starting_indexes.decadeindex, starting_indexes.decadeindex,
&self.yearindex,
&indexes.decadeindex_to_first_yearindex,
&indexes.decadeindex_to_yearindex_count, &indexes.decadeindex_to_yearindex_count,
exit, exit,
)?; )?;
@@ -243,6 +269,7 @@ where
self.difficultyepoch.vecs(), self.difficultyepoch.vecs(),
self.monthindex.vecs(), self.monthindex.vecs(),
self.quarterindex.vecs(), self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(), self.yearindex.vecs(),
// self.halvingepoch.vecs(), // self.halvingepoch.vecs(),
self.decadeindex.vecs(), self.decadeindex.vecs(),
@@ -5,9 +5,9 @@ use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, EagerVec, Format}; 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)] #[derive(Clone)]
pub struct ComputedVecsFromHeightStrict<T> pub struct ComputedVecsFromHeightStrict<T>
@@ -15,8 +15,8 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub height: EagerVec<Height, T>, pub height: EagerVec<Height, T>,
pub height_extra: ComputedVecBuilder<Height, T>, pub height_extra: EagerVecBuilder<Height, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>, pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>, // TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
} }
@@ -32,12 +32,12 @@ where
name: &str, name: &str,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let height = let height =
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)?; EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)?;
let height_extra = ComputedVecBuilder::forced_import( let height_extra = EagerVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -50,7 +50,7 @@ where
Ok(Self { Ok(Self {
height, height,
height_extra, height_extra,
difficultyepoch: ComputedVecBuilder::forced_import( difficultyepoch: EagerVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -2,17 +2,22 @@ use std::path::Path;
use brk_core::{ use brk_core::{
Bitcoin, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, MonthIndex, QuarterIndex, 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_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{ 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)] #[derive(Clone)]
pub struct ComputedVecsFromTxindex<T> pub struct ComputedVecsFromTxindex<T>
@@ -20,40 +25,42 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub txindex: Option<Box<EagerVec<TxIndex, T>>>, pub txindex: Option<Box<EagerVec<TxIndex, T>>>,
pub height: ComputedVecBuilder<Height, T>, pub height: EagerVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<DateIndex, T>, pub dateindex: EagerVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>, pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>, pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>, pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>, pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T>, pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>, // TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>, pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex>,
} }
const VERSION: Version = Version::ZERO; const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromTxindex<T> impl<T> ComputedVecsFromTxindex<T>
where where
T: ComputedType + Ord + From<f64>, T: ComputedType + Ord + From<f64> + 'static,
f64: From<T>, f64: From<T>,
{ {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<TxIndex, T>,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, computation: Computation,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let txindex = compute_source.then(|| { let txindex = source.is_compute().then(|| {
Box::new( Box::new(
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format) EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
.unwrap(), .unwrap(),
) )
}); });
let height = ComputedVecBuilder::forced_import( let height = EagerVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -63,45 +70,80 @@ where
let options = options.remove_percentiles(); let options = options.remove_percentiles();
let dateindex = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?;
Ok(Self { Ok(Self {
txindex,
height,
dateindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?,
weekindex: ComputedVecBuilder::forced_import( weekindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
)?, None,
difficultyepoch: ComputedVecBuilder::forced_import( &dateindex,
path, options.into(),
name,
version + VERSION + Version::ZERO,
format,
options,
)?, )?,
monthindex: ComputedVecBuilder::forced_import( monthindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
options, computation,
None,
&dateindex,
options.into(),
)?, )?,
quarterindex: ComputedVecBuilder::forced_import( quarterindex: ComputedVecBuilder::forced_import(
path, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, 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( 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, path,
name, name,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
@@ -109,13 +151,6 @@ where
options, options,
)?, )?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, 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, exit,
)?; )?;
self.weekindex.from_aligned( self.weekindex.compute_if_necessary(
starting_indexes.weekindex, starting_indexes.weekindex,
&self.dateindex,
&indexes.weekindex_to_first_dateindex, &indexes.weekindex_to_first_dateindex,
&indexes.weekindex_to_dateindex_count,
exit, exit,
)?; )?;
self.monthindex.from_aligned( self.monthindex.compute_if_necessary(
starting_indexes.monthindex, starting_indexes.monthindex,
&self.dateindex,
&indexes.monthindex_to_first_dateindex,
&indexes.monthindex_to_dateindex_count, &indexes.monthindex_to_dateindex_count,
exit, exit,
)?; )?;
self.quarterindex.from_aligned( self.quarterindex.compute_if_necessary(
starting_indexes.quarterindex, starting_indexes.quarterindex,
&self.monthindex,
&indexes.quarterindex_to_first_monthindex,
&indexes.quarterindex_to_monthindex_count, &indexes.quarterindex_to_monthindex_count,
exit, 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, starting_indexes.yearindex,
&self.monthindex,
&indexes.yearindex_to_first_monthindex,
&indexes.yearindex_to_monthindex_count, &indexes.yearindex_to_monthindex_count,
exit, exit,
)?; )?;
self.decadeindex.from_aligned( self.decadeindex.compute_if_necessary(
starting_indexes.decadeindex, starting_indexes.decadeindex,
&self.yearindex,
&indexes.decadeindex_to_first_yearindex,
&indexes.decadeindex_to_yearindex_count, &indexes.decadeindex_to_yearindex_count,
exit, exit,
)?; )?;
@@ -258,6 +289,7 @@ where
self.difficultyepoch.vecs(), self.difficultyepoch.vecs(),
self.monthindex.vecs(), self.monthindex.vecs(),
self.quarterindex.vecs(), self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(), self.yearindex.vecs(),
// self.halvingepoch.vecs(), // self.halvingepoch.vecs(),
self.decadeindex.vecs(), self.decadeindex.vecs(),
+6 -2
View File
@@ -1,21 +1,25 @@
mod builder; mod builder_computed;
mod builder_eager;
mod from_dateindex; mod from_dateindex;
mod from_height; mod from_height;
mod from_height_strict; mod from_height_strict;
mod from_txindex; mod from_txindex;
mod ratio_from_dateindex; mod ratio_from_dateindex;
mod source;
mod r#type; mod r#type;
mod value_from_dateindex; mod value_from_dateindex;
mod value_from_height; mod value_from_height;
mod value_from_txindex; mod value_from_txindex;
mod value_height; mod value_height;
pub use builder::*; pub use builder_computed::*;
pub use builder_eager::*;
pub use from_dateindex::*; pub use from_dateindex::*;
pub use from_height::*; pub use from_height::*;
pub use from_height_strict::*; pub use from_height_strict::*;
pub use from_txindex::*; pub use from_txindex::*;
pub use ratio_from_dateindex::*; pub use ratio_from_dateindex::*;
pub use source::*;
use r#type::*; use r#type::*;
pub use value_from_dateindex::*; pub use value_from_dateindex::*;
pub use value_from_height::*; pub use value_from_height::*;
@@ -4,16 +4,16 @@ use brk_core::{Date, DateIndex, Dollars, Result, StoredF32, Version};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{ use brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex, AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, Computation, EagerVec, Format,
VecIterator, StoredIndex, VecIterator,
}; };
use crate::{ use crate::{
utils::get_percentile, utils::get_percentile,
vecs::{Indexes, fetched, indexes}, vecs::{Indexes, fetched, grouped::source::Source, indexes},
}; };
use super::{ComputedVecsFromDateIndex, StorableVecGeneatorOptions}; use super::{ComputedVecsFromDateIndex, EagerVecBuilderOptions};
#[derive(Clone)] #[derive(Clone)]
pub struct ComputedRatioVecsFromDateIndex { pub struct ComputedRatioVecsFromDateIndex {
@@ -64,20 +64,22 @@ impl ComputedRatioVecsFromDateIndex {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<DateIndex, Dollars>,
version: Version, version: Version,
format: Format, format: Format,
computation: Computation,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let options = StorableVecGeneatorOptions::default().add_last(); let options = EagerVecBuilderOptions::default().add_last();
Ok(Self { Ok(Self {
price: compute_source.then(|| { price: source.is_compute().then(|| {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
name, name,
true, Source::Compute,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
) )
.unwrap() .unwrap()
@@ -85,297 +87,334 @@ impl ComputedRatioVecsFromDateIndex {
ratio: ComputedVecsFromDateIndex::forced_import( ratio: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio"), &format!("{name}_ratio"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_sma: ComputedVecsFromDateIndex::forced_import( ratio_sma: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_sma"), &format!("{name}_ratio_sma"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_1w_sma: ComputedVecsFromDateIndex::forced_import( ratio_1w_sma: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_1w_sma"), &format!("{name}_ratio_1w_sma"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_1m_sma: ComputedVecsFromDateIndex::forced_import( ratio_1m_sma: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_1m_sma"), &format!("{name}_ratio_1m_sma"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_1y_sma: ComputedVecsFromDateIndex::forced_import( ratio_1y_sma: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_1y_sma"), &format!("{name}_ratio_1y_sma"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_4y_sma: ComputedVecsFromDateIndex::forced_import( ratio_4y_sma: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_4y_sma"), &format!("{name}_ratio_4y_sma"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex::forced_import( ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_1y_sma_momentum_oscillator"), &format!("{name}_ratio_1y_sma_momentum_oscillator"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_sd: ComputedVecsFromDateIndex::forced_import( ratio_sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_sd"), &format!("{name}_ratio_sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_4y_sd: ComputedVecsFromDateIndex::forced_import( ratio_4y_sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_4y_sd"), &format!("{name}_ratio_4y_sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_1y_sd: ComputedVecsFromDateIndex::forced_import( ratio_1y_sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_1y_sd"), &format!("{name}_ratio_1y_sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p99_9: ComputedVecsFromDateIndex::forced_import( ratio_p99_9: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p99_9"), &format!("{name}_ratio_p99_9"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p99_5: ComputedVecsFromDateIndex::forced_import( ratio_p99_5: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p99_5"), &format!("{name}_ratio_p99_5"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p99: ComputedVecsFromDateIndex::forced_import( ratio_p99: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p99"), &format!("{name}_ratio_p99"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p1: ComputedVecsFromDateIndex::forced_import( ratio_p1: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p1"), &format!("{name}_ratio_p1"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p0_5: ComputedVecsFromDateIndex::forced_import( ratio_p0_5: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p0_5"), &format!("{name}_ratio_p0_5"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p0_1: ComputedVecsFromDateIndex::forced_import( ratio_p0_1: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p0_1"), &format!("{name}_ratio_p0_1"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p1sd: ComputedVecsFromDateIndex::forced_import( ratio_p1sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p1sd"), &format!("{name}_ratio_p1sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p2sd: ComputedVecsFromDateIndex::forced_import( ratio_p2sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p2sd"), &format!("{name}_ratio_p2sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p3sd: ComputedVecsFromDateIndex::forced_import( ratio_p3sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p3sd"), &format!("{name}_ratio_p3sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_m1sd: ComputedVecsFromDateIndex::forced_import( ratio_m1sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_m1sd"), &format!("{name}_ratio_m1sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_m2sd: ComputedVecsFromDateIndex::forced_import( ratio_m2sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_m2sd"), &format!("{name}_ratio_m2sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_m3sd: ComputedVecsFromDateIndex::forced_import( ratio_m3sd: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_m3sd"), &format!("{name}_ratio_m3sd"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p99_9_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p99_9_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p99_9_as_price"), &format!("{name}_ratio_p99_9_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p99_5_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p99_5_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p99_5_as_price"), &format!("{name}_ratio_p99_5_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p99_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p99_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p99_as_price"), &format!("{name}_ratio_p99_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p1_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p1_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p1_as_price"), &format!("{name}_ratio_p1_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p0_5_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p0_5_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p0_5_as_price"), &format!("{name}_ratio_p0_5_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p0_1_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p0_1_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p0_1_as_price"), &format!("{name}_ratio_p0_1_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p1sd_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p1sd_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p1sd_as_price"), &format!("{name}_ratio_p1sd_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p2sd_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p2sd_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p2sd_as_price"), &format!("{name}_ratio_p2sd_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_p3sd_as_price: ComputedVecsFromDateIndex::forced_import( ratio_p3sd_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_p3sd_as_price"), &format!("{name}_ratio_p3sd_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_m1sd_as_price: ComputedVecsFromDateIndex::forced_import( ratio_m1sd_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_m1sd_as_price"), &format!("{name}_ratio_m1sd_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_m2sd_as_price: ComputedVecsFromDateIndex::forced_import( ratio_m2sd_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_m2sd_as_price"), &format!("{name}_ratio_m2sd_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_m3sd_as_price: ComputedVecsFromDateIndex::forced_import( ratio_m3sd_as_price: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_m3sd_as_price"), &format!("{name}_ratio_m3sd_as_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_zscore: ComputedVecsFromDateIndex::forced_import( ratio_zscore: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_zscore"), &format!("{name}_ratio_zscore"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_4y_zscore: ComputedVecsFromDateIndex::forced_import( ratio_4y_zscore: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_4y_zscore"), &format!("{name}_ratio_4y_zscore"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
ratio_1y_zscore: ComputedVecsFromDateIndex::forced_import( ratio_1y_zscore: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_ratio_1y_zscore"), &format!("{name}_ratio_1y_zscore"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
options, options,
)?, )?,
}) })
@@ -0,0 +1,51 @@
use brk_vec::BoxedAnyIterableVec;
#[derive(Clone)]
pub enum Source<I, T> {
Compute,
None,
Vec(BoxedAnyIterableVec<I, T>),
}
impl<I, T> Source<I, T> {
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<BoxedAnyIterableVec<I, T>> {
match self {
Self::Vec(v) => Some(v),
_ => None,
}
}
}
impl<I, T> From<bool> for Source<I, T> {
fn from(value: bool) -> Self {
if value { Self::Compute } else { Self::None }
}
}
impl<I, T> From<BoxedAnyIterableVec<I, T>> for Source<I, T> {
fn from(value: BoxedAnyIterableVec<I, T>) -> Self {
Self::Vec(value)
}
}
impl<I, T> From<Option<BoxedAnyIterableVec<I, T>>> for Source<I, T> {
fn from(value: Option<BoxedAnyIterableVec<I, T>>) -> Self {
if let Some(v) = value {
Self::Vec(v)
} else {
Self::None
}
}
}
+4 -3
View File
@@ -1,13 +1,14 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use brk_vec::StoredType; use brk_vec::StoredType;
pub trait ComputedType pub trait ComputedType
where where
Self: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + Ord, Self:
StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + AddAssign + Ord,
{ {
} }
impl<T> ComputedType for T where impl<T> ComputedType for T where
T: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + Ord T: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + AddAssign + Ord
{ {
} }
@@ -3,11 +3,11 @@ use std::path::Path;
use brk_core::{Bitcoin, DateIndex, Dollars, Result, Sats, Version}; use brk_core::{Bitcoin, DateIndex, Dollars, Result, Sats, Version};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; 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 crate::vecs::{Indexes, fetched, grouped::ComputedVecsFromDateIndex, indexes};
use super::StorableVecGeneatorOptions; use super::{EagerVecBuilderOptions, Source};
#[derive(Clone)] #[derive(Clone)]
pub struct ComputedValueVecsFromDateIndex { pub struct ComputedValueVecsFromDateIndex {
@@ -19,39 +19,44 @@ pub struct ComputedValueVecsFromDateIndex {
const VERSION: Version = Version::ZERO; const VERSION: Version = Version::ZERO;
impl ComputedValueVecsFromDateIndex { impl ComputedValueVecsFromDateIndex {
#[allow(clippy::too_many_arguments)]
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<DateIndex, Sats>,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, computation: Computation,
options: EagerVecBuilderOptions,
compute_dollars: bool, compute_dollars: bool,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
sats: ComputedVecsFromDateIndex::forced_import( sats: ComputedVecsFromDateIndex::forced_import(
path, path,
name, name,
compute_source, source,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
)?, )?,
bitcoin: ComputedVecsFromDateIndex::forced_import( bitcoin: ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_in_btc"), &format!("{name}_in_btc"),
true, Source::Compute,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
)?, )?,
dollars: compute_dollars.then(|| { dollars: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&format!("{name}_in_usd"), &format!("{name}_in_usd"),
true, Source::Compute,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
) )
.unwrap() .unwrap()
@@ -3,11 +3,11 @@ use std::path::Path;
use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version}; use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; 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)] #[derive(Clone)]
pub struct ComputedValueVecsFromHeight { pub struct ComputedValueVecsFromHeight {
@@ -19,39 +19,44 @@ pub struct ComputedValueVecsFromHeight {
const VERSION: Version = Version::ZERO; const VERSION: Version = Version::ZERO;
impl ComputedValueVecsFromHeight { impl ComputedValueVecsFromHeight {
#[allow(clippy::too_many_arguments)]
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<Height, Sats>,
version: Version, version: Version,
format: Format, format: Format,
options: StorableVecGeneatorOptions, computation: Computation,
options: EagerVecBuilderOptions,
compute_dollars: bool, compute_dollars: bool,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
sats: ComputedVecsFromHeight::forced_import( sats: ComputedVecsFromHeight::forced_import(
path, path,
name, name,
compute_source, source,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
)?, )?,
bitcoin: ComputedVecsFromHeight::forced_import( bitcoin: ComputedVecsFromHeight::forced_import(
path, path,
&format!("{name}_in_btc"), &format!("{name}_in_btc"),
true, Source::Compute,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
)?, )?,
dollars: compute_dollars.then(|| { dollars: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&format!("{name}_in_usd"), &format!("{name}_in_usd"),
true, Source::Compute,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
) )
.unwrap() .unwrap()
@@ -4,13 +4,13 @@ use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{ use brk_vec::{
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Computation, AnyCollectableVec, CloneableAnyIterableVec, CollectableVec, Computation, ComputedVecFrom3,
ComputedVecFrom3, Format, LazyVecFrom1, StoredIndex, StoredVec, 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)] #[derive(Clone)]
pub struct ComputedValueVecsFromTxindex { pub struct ComputedValueVecsFromTxindex {
@@ -41,14 +41,13 @@ impl ComputedValueVecsFromTxindex {
path: &Path, path: &Path,
name: &str, name: &str,
indexes: &indexes::Vecs, indexes: &indexes::Vecs,
source: Option<BoxedAnyIterableVec<TxIndex, Sats>>, source: Source<TxIndex, Sats>,
version: Version, version: Version,
computation: Computation, computation: Computation,
format: Format, format: Format,
fetched: Option<&fetched::Vecs>, fetched: Option<&fetched::Vecs>,
options: StorableVecGeneatorOptions, options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let compute_source = source.is_none();
let compute_dollars = fetched.is_some(); let compute_dollars = fetched.is_some();
let name_in_btc = format!("{name}_in_btc"); let name_in_btc = format!("{name}_in_btc");
@@ -57,16 +56,19 @@ impl ComputedValueVecsFromTxindex {
let sats = ComputedVecsFromTxindex::forced_import( let sats = ComputedVecsFromTxindex::forced_import(
path, path,
name, name,
compute_source, source.clone(),
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
)?; )?;
let source_vec = source.vec();
let bitcoin_txindex = LazyVecFrom1::init( let bitcoin_txindex = LazyVecFrom1::init(
&name_in_btc, &name_in_btc,
version + VERSION, 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| { |txindex: TxIndex, iter| {
iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| { iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| {
let sats = value.into_owned(); let sats = value.into_owned();
@@ -78,9 +80,10 @@ impl ComputedValueVecsFromTxindex {
let bitcoin = ComputedVecsFromTxindex::forced_import( let bitcoin = ComputedVecsFromTxindex::forced_import(
path, path,
&name_in_btc, &name_in_btc,
false, Source::None,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
)?; )?;
@@ -124,9 +127,10 @@ impl ComputedValueVecsFromTxindex {
ComputedVecsFromTxindex::forced_import( ComputedVecsFromTxindex::forced_import(
path, path,
&name_in_usd, &name_in_usd,
false, Source::None,
version + VERSION, version + VERSION,
format, format,
computation,
options, options,
) )
.unwrap() .unwrap()
@@ -5,7 +5,7 @@ use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec}; use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
use crate::vecs::{Indexes, fetched, indexes}; use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
#[derive(Clone)] #[derive(Clone)]
pub struct ComputedHeightValueVecs { pub struct ComputedHeightValueVecs {
@@ -20,13 +20,13 @@ impl ComputedHeightValueVecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool, source: Source<Height, Sats>,
version: Version, version: Version,
format: Format, format: Format,
compute_dollars: bool, compute_dollars: bool,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
sats: compute_source.then(|| { sats: source.is_compute().then(|| {
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format) EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
.unwrap() .unwrap()
}), }),
+76 -2
View File
@@ -5,8 +5,8 @@ use brk_core::{
InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2ABytes, P2MSOutputIndex, InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2ABytes, P2MSOutputIndex,
P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, P2PKHAddressIndex, P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, P2PKHAddressIndex,
P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, P2WPKHAddressIndex, P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, P2WPKHAddressIndex,
P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, StoredUsize, Timestamp, P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, SemesterIndex, StoredUsize,
TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex, Timestamp, TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex,
}; };
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
@@ -50,6 +50,7 @@ pub struct Vecs {
pub monthindex_to_first_dateindex: EagerVec<MonthIndex, DateIndex>, pub monthindex_to_first_dateindex: EagerVec<MonthIndex, DateIndex>,
pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>, pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>,
pub monthindex_to_quarterindex: EagerVec<MonthIndex, QuarterIndex>, pub monthindex_to_quarterindex: EagerVec<MonthIndex, QuarterIndex>,
pub monthindex_to_semesterindex: EagerVec<MonthIndex, SemesterIndex>,
pub monthindex_to_yearindex: EagerVec<MonthIndex, YearIndex>, pub monthindex_to_yearindex: EagerVec<MonthIndex, YearIndex>,
pub opreturnindex_to_opreturnindex: pub opreturnindex_to_opreturnindex:
ComputedVecFrom1<OpReturnIndex, OpReturnIndex, OpReturnIndex, TxIndex>, ComputedVecFrom1<OpReturnIndex, OpReturnIndex, OpReturnIndex, TxIndex>,
@@ -76,6 +77,9 @@ pub struct Vecs {
pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>, pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>,
pub quarterindex_to_monthindex_count: EagerVec<QuarterIndex, StoredUsize>, pub quarterindex_to_monthindex_count: EagerVec<QuarterIndex, StoredUsize>,
pub quarterindex_to_quarterindex: EagerVec<QuarterIndex, QuarterIndex>, pub quarterindex_to_quarterindex: EagerVec<QuarterIndex, QuarterIndex>,
pub semesterindex_to_first_monthindex: EagerVec<SemesterIndex, MonthIndex>,
pub semesterindex_to_monthindex_count: EagerVec<SemesterIndex, StoredUsize>,
pub semesterindex_to_semesterindex: EagerVec<SemesterIndex, SemesterIndex>,
pub txindex_to_height: EagerVec<TxIndex, Height>, pub txindex_to_height: EagerVec<TxIndex, Height>,
pub txindex_to_input_count: pub txindex_to_input_count:
ComputedVecFrom2<TxIndex, StoredUsize, TxIndex, InputIndex, InputIndex, OutputIndex>, ComputedVecFrom2<TxIndex, StoredUsize, TxIndex, InputIndex, InputIndex, OutputIndex>,
@@ -413,6 +417,12 @@ impl Vecs {
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
)?, )?,
monthindex_to_semesterindex: EagerVec::forced_import(
path,
"semesterindex",
version + VERSION + Version::ZERO,
format,
)?,
monthindex_to_yearindex: EagerVec::forced_import( monthindex_to_yearindex: EagerVec::forced_import(
path, path,
"yearindex", "yearindex",
@@ -425,6 +435,12 @@ impl Vecs {
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
)?, )?,
semesterindex_to_first_monthindex: EagerVec::forced_import(
path,
"first_monthindex",
version + VERSION + Version::ZERO,
format,
)?,
weekindex_to_first_dateindex: EagerVec::forced_import( weekindex_to_first_dateindex: EagerVec::forced_import(
path, path,
"first_dateindex", "first_dateindex",
@@ -443,6 +459,12 @@ impl Vecs {
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
)?, )?,
semesterindex_to_semesterindex: EagerVec::forced_import(
path,
"semesterindex",
version + VERSION + Version::ZERO,
format,
)?,
weekindex_to_weekindex: EagerVec::forced_import( weekindex_to_weekindex: EagerVec::forced_import(
path, path,
"weekindex", "weekindex",
@@ -521,6 +543,12 @@ impl Vecs {
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
)?, )?,
semesterindex_to_monthindex_count: EagerVec::forced_import(
path,
"monthindex_count",
version + VERSION + Version::ZERO,
format,
)?,
yearindex_to_monthindex_count: EagerVec::forced_import( yearindex_to_monthindex_count: EagerVec::forced_import(
path, path,
"monthindex_count", "monthindex_count",
@@ -943,6 +971,45 @@ impl Vecs {
exit, 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 // YearIndex
// --- // ---
@@ -1051,6 +1118,7 @@ impl Vecs {
weekindex: starting_weekindex, weekindex: starting_weekindex,
monthindex: starting_monthindex, monthindex: starting_monthindex,
quarterindex: starting_quarterindex, quarterindex: starting_quarterindex,
semesterindex: starting_semesterindex,
yearindex: starting_yearindex, yearindex: starting_yearindex,
decadeindex: starting_decadeindex, decadeindex: starting_decadeindex,
difficultyepoch: starting_difficultyepoch, difficultyepoch: starting_difficultyepoch,
@@ -1088,6 +1156,7 @@ impl Vecs {
&self.monthindex_to_first_dateindex, &self.monthindex_to_first_dateindex,
&self.monthindex_to_monthindex, &self.monthindex_to_monthindex,
&self.monthindex_to_quarterindex, &self.monthindex_to_quarterindex,
&self.monthindex_to_semesterindex,
&self.monthindex_to_yearindex, &self.monthindex_to_yearindex,
&self.opreturnindex_to_opreturnindex, &self.opreturnindex_to_opreturnindex,
&self.outputindex_to_outputindex, &self.outputindex_to_outputindex,
@@ -1103,6 +1172,9 @@ impl Vecs {
&self.quarterindex_to_first_monthindex, &self.quarterindex_to_first_monthindex,
&self.quarterindex_to_monthindex_count, &self.quarterindex_to_monthindex_count,
&self.quarterindex_to_quarterindex, &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_height,
&self.txindex_to_txindex, &self.txindex_to_txindex,
&self.txindex_to_input_count, &self.txindex_to_input_count,
@@ -1126,6 +1198,7 @@ pub struct Indexes {
pub weekindex: WeekIndex, pub weekindex: WeekIndex,
pub monthindex: MonthIndex, pub monthindex: MonthIndex,
pub quarterindex: QuarterIndex, pub quarterindex: QuarterIndex,
pub semesterindex: SemesterIndex,
pub yearindex: YearIndex, pub yearindex: YearIndex,
pub decadeindex: DecadeIndex, pub decadeindex: DecadeIndex,
pub difficultyepoch: DifficultyEpoch, pub difficultyepoch: DifficultyEpoch,
@@ -1145,6 +1218,7 @@ impl Indexes {
self.weekindex = WeekIndex::from(self.dateindex); self.weekindex = WeekIndex::from(self.dateindex);
self.monthindex = MonthIndex::from(self.dateindex); self.monthindex = MonthIndex::from(self.dateindex);
self.quarterindex = QuarterIndex::from(self.monthindex); self.quarterindex = QuarterIndex::from(self.monthindex);
self.semesterindex = SemesterIndex::from(self.monthindex);
self.yearindex = YearIndex::from(self.monthindex); self.yearindex = YearIndex::from(self.monthindex);
self.decadeindex = DecadeIndex::from(self.dateindex); self.decadeindex = DecadeIndex::from(self.dateindex);
self.difficultyepoch = DifficultyEpoch::from(self.height); self.difficultyepoch = DifficultyEpoch::from(self.height);
File diff suppressed because it is too large Load Diff
+13 -8
View File
@@ -5,9 +5,11 @@ use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator}; use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
use crate::vecs::grouped::Source;
use super::{ use super::{
Indexes, Indexes,
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes, indexes,
}; };
@@ -24,33 +26,36 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
version: Version, version: Version,
_computation: Computation, computation: Computation,
format: Format, format: Format,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
indexes_to_difficulty: ComputedVecsFromHeight::forced_import( indexes_to_difficulty: ComputedVecsFromHeight::forced_import(
path, path,
"difficulty", "difficulty",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import( indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
path, path,
"difficultyepoch", "difficultyepoch",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import( indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import(
path, path,
"halvingepoch", "halvingepoch",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
}) })
} }
@@ -11,7 +11,7 @@ use crate::{
states::AddressCohortState, states::AddressCohortState,
vecs::{ vecs::{
Indexes, fetched, Indexes, fetched,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions, Source},
indexes, market, indexes, market,
stateful::{ stateful::{
common, common,
@@ -66,10 +66,11 @@ impl Vecs {
indexes_to_address_count: ComputedVecsFromHeight::forced_import( indexes_to_address_count: ComputedVecsFromHeight::forced_import(
path, path,
&suffix("address_count"), &suffix("address_count"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
inner: common::Vecs::forced_import( inner: common::Vecs::forced_import(
path, path,
+186 -135
View File
@@ -6,7 +6,8 @@ use brk_core::{
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{ use brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, Format, VecIterator, AnyCollectableVec, AnyIterableVec, AnyVec, CloneableAnyIterableVec, Computation, EagerVec,
Format, VecIterator,
}; };
use crate::{ use crate::{
@@ -16,7 +17,7 @@ use crate::{
grouped::{ grouped::{
ComputedHeightValueVecs, ComputedRatioVecsFromDateIndex, ComputedHeightValueVecs, ComputedRatioVecsFromDateIndex,
ComputedValueVecsFromDateIndex, ComputedVecsFromDateIndex, ComputedVecsFromHeight, ComputedValueVecsFromDateIndex, ComputedVecsFromDateIndex, ComputedVecsFromHeight,
StorableVecGeneatorOptions, EagerVecBuilderOptions, Source,
}, },
indexes, market, indexes, market,
}, },
@@ -132,7 +133,7 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
cohort_name: Option<&str>, cohort_name: Option<&str>,
_computation: Computation, computation: Computation,
format: Format, format: Format,
version: Version, version: Version,
fetched: Option<&fetched::Vecs>, 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}")); 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(|| { height_to_supply_in_profit: compute_dollars.then(|| {
EagerVec::forced_import( EagerVec::forced_import(
path, path,
@@ -155,27 +205,20 @@ impl Vecs {
) )
.unwrap() .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(|| { indexes_to_supply_in_profit: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import( ComputedValueVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_in_profit"), &suffix("supply_in_profit"),
false, dateindex_to_supply_in_profit.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
) )
.unwrap() .unwrap()
}), }),
dateindex_to_supply_in_profit,
height_to_supply_even: compute_dollars.then(|| { height_to_supply_even: compute_dollars.then(|| {
EagerVec::forced_import( EagerVec::forced_import(
path, path,
@@ -185,27 +228,20 @@ impl Vecs {
) )
.unwrap() .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(|| { indexes_to_supply_even: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import( ComputedValueVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_even"), &suffix("supply_even"),
false, dateindex_to_supply_even.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
) )
.unwrap() .unwrap()
}), }),
dateindex_to_supply_even,
height_to_supply_in_loss: compute_dollars.then(|| { height_to_supply_in_loss: compute_dollars.then(|| {
EagerVec::forced_import( EagerVec::forced_import(
path, path,
@@ -215,27 +251,20 @@ impl Vecs {
) )
.unwrap() .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(|| { indexes_to_supply_in_loss: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import( ComputedValueVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_in_loss"), &suffix("supply_in_loss"),
false, dateindex_to_supply_in_loss.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
) )
.unwrap() .unwrap()
}), }),
dateindex_to_supply_in_loss,
height_to_unrealized_profit: compute_dollars.then(|| { height_to_unrealized_profit: compute_dollars.then(|| {
EagerVec::forced_import( EagerVec::forced_import(
path, path,
@@ -245,26 +274,19 @@ impl Vecs {
) )
.unwrap() .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(|| { indexes_to_unrealized_profit: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("unrealized_profit"), &suffix("unrealized_profit"),
false, dateindex_to_unrealized_profit.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
dateindex_to_unrealized_profit,
height_to_unrealized_loss: compute_dollars.then(|| { height_to_unrealized_loss: compute_dollars.then(|| {
EagerVec::forced_import( EagerVec::forced_import(
path, path,
@@ -292,26 +314,19 @@ impl Vecs {
) )
.unwrap() .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(|| { indexes_to_unrealized_loss: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("unrealized_loss"), &suffix("unrealized_loss"),
false, dateindex_to_unrealized_loss.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
dateindex_to_unrealized_loss,
height_to_realized_cap: compute_dollars.then(|| { height_to_realized_cap: compute_dollars.then(|| {
EagerVec::forced_import( EagerVec::forced_import(
path, path,
@@ -325,10 +340,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_cap"), &suffix("realized_cap"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -336,10 +352,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("min_price_paid"), &suffix("min_price_paid"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -347,10 +364,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("max_price_paid"), &suffix("max_price_paid"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -363,7 +381,7 @@ impl Vecs {
height_to_supply_value: ComputedHeightValueVecs::forced_import( height_to_supply_value: ComputedHeightValueVecs::forced_import(
path, path,
&suffix("supply"), &suffix("supply"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
compute_dollars, compute_dollars,
@@ -371,10 +389,11 @@ impl Vecs {
indexes_to_supply: ComputedValueVecsFromDateIndex::forced_import( indexes_to_supply: ComputedValueVecsFromDateIndex::forced_import(
path, path,
&suffix("supply"), &suffix("supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
)?, )?,
height_to_utxo_count: EagerVec::forced_import( height_to_utxo_count: EagerVec::forced_import(
@@ -386,19 +405,21 @@ impl Vecs {
indexes_to_utxo_count: ComputedVecsFromHeight::forced_import( indexes_to_utxo_count: ComputedVecsFromHeight::forced_import(
path, path,
&suffix("utxo_count"), &suffix("utxo_count"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_realized_price: compute_dollars.then(|| { indexes_to_realized_price: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_price"), &suffix("realized_price"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -406,9 +427,10 @@ impl Vecs {
ComputedRatioVecsFromDateIndex::forced_import( ComputedRatioVecsFromDateIndex::forced_import(
path, path,
&suffix("realized_price"), &suffix("realized_price"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
computation,
) )
.unwrap() .unwrap()
}), }),
@@ -425,10 +447,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_profit"), &suffix("realized_profit"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_sum() .add_sum()
.add_cumulative(), .add_cumulative(),
) )
@@ -447,10 +470,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_loss"), &suffix("realized_loss"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_sum() .add_sum()
.add_cumulative(), .add_cumulative(),
) )
@@ -460,10 +484,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("negative_realized_loss"), &suffix("negative_realized_loss"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_sum().add_cumulative(), computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
) )
.unwrap() .unwrap()
}), }),
@@ -480,10 +505,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("value_created"), &suffix("value_created"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -491,10 +517,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_value"), &suffix("realized_value"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -511,10 +538,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("adjusted_value_created"), &suffix("adjusted_value_created"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -531,10 +559,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("value_destroyed"), &suffix("value_destroyed"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -551,10 +580,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("adjusted_value_destroyed"), &suffix("adjusted_value_destroyed"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -562,10 +592,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("realized_cap_30d_change"), &suffix("realized_cap_30d_change"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -573,10 +604,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("net_realized_profit_and_loss"), &suffix("net_realized_profit_and_loss"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_sum() .add_sum()
.add_cumulative(), .add_cumulative(),
) )
@@ -612,7 +644,7 @@ impl Vecs {
height_to_halved_supply_value: ComputedHeightValueVecs::forced_import( height_to_halved_supply_value: ComputedHeightValueVecs::forced_import(
path, path,
&suffix("halved_supply"), &suffix("halved_supply"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
compute_dollars, compute_dollars,
@@ -620,10 +652,11 @@ impl Vecs {
indexes_to_halved_supply: ComputedValueVecsFromDateIndex::forced_import( indexes_to_halved_supply: ComputedValueVecsFromDateIndex::forced_import(
path, path,
&suffix("halved_supply"), &suffix("halved_supply"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
)?, )?,
height_to_negative_unrealized_loss: compute_dollars.then(|| { height_to_negative_unrealized_loss: compute_dollars.then(|| {
@@ -639,10 +672,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("negative_unrealized_loss"), &suffix("negative_unrealized_loss"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -659,10 +693,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("net_unrealized_profit_and_loss"), &suffix("net_unrealized_profit_and_loss"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -682,10 +717,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("net_unrealized_profit_and_loss_relative_to_market_cap"), &suffix("net_unrealized_profit_and_loss_relative_to_market_cap"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}, },
@@ -694,10 +730,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_profit_relative_to_realized_cap"), &suffix("realized_profit_relative_to_realized_cap"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -705,10 +742,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("realized_loss_relative_to_realized_cap"), &suffix("realized_loss_relative_to_realized_cap"),
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}), }),
@@ -717,10 +755,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("net_realized_profit_and_loss_relative_to_realized_cap"), &suffix("net_realized_profit_and_loss_relative_to_realized_cap"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_sum(), computation,
EagerVecBuilderOptions::default().add_sum(),
) )
.unwrap() .unwrap()
}, },
@@ -729,7 +768,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import( ComputedHeightValueVecs::forced_import(
path, path,
&suffix("supply_even"), &suffix("supply_even"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
compute_dollars, compute_dollars,
@@ -740,7 +779,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import( ComputedHeightValueVecs::forced_import(
path, path,
&suffix("supply_in_loss"), &suffix("supply_in_loss"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
compute_dollars, compute_dollars,
@@ -751,7 +790,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import( ComputedHeightValueVecs::forced_import(
path, path,
&suffix("supply_in_profit"), &suffix("supply_in_profit"),
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
compute_dollars, compute_dollars,
@@ -789,10 +828,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_even_relative_to_own_supply"), &suffix("supply_even_relative_to_own_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -800,10 +840,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_in_loss_relative_to_own_supply"), &suffix("supply_in_loss_relative_to_own_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -811,10 +852,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_in_profit_relative_to_own_supply"), &suffix("supply_in_profit_relative_to_own_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -822,10 +864,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import( ComputedVecsFromHeight::forced_import(
path, path,
&suffix("supply_relative_to_circulating_supply"), &suffix("supply_relative_to_circulating_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -868,10 +911,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_even_relative_to_circulating_supply"), &suffix("supply_even_relative_to_circulating_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -881,10 +925,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_in_loss_relative_to_circulating_supply"), &suffix("supply_in_loss_relative_to_circulating_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -894,10 +939,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("supply_in_profit_relative_to_circulating_supply"), &suffix("supply_in_profit_relative_to_circulating_supply"),
true, Source::Compute,
version + VERSION + Version::ONE, version + VERSION + Version::ONE,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
) )
.unwrap() .unwrap()
}), }),
@@ -916,27 +962,30 @@ impl Vecs {
indexes_to_coinblocks_destroyed: ComputedVecsFromHeight::forced_import( indexes_to_coinblocks_destroyed: ComputedVecsFromHeight::forced_import(
path, path,
&suffix("coinblocks_destroyed"), &suffix("coinblocks_destroyed"),
true, Source::Compute,
version + VERSION + Version::TWO, version + VERSION + Version::TWO,
format, format,
StorableVecGeneatorOptions::default().add_sum().add_cumulative(), computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?, )?,
indexes_to_coindays_destroyed: ComputedVecsFromHeight::forced_import( indexes_to_coindays_destroyed: ComputedVecsFromHeight::forced_import(
path, path,
&suffix("coindays_destroyed"), &suffix("coindays_destroyed"),
true, Source::Compute,
version + VERSION + Version::TWO, version + VERSION + Version::TWO,
format, 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(|| { indexes_to_net_realized_profit_and_loss_cumulative_30d_change: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("net_realized_profit_and_loss_cumulative_30d_change"), &suffix("net_realized_profit_and_loss_cumulative_30d_change"),
true, Source::Compute,
version + VERSION + Version::new(3), version + VERSION + Version::new(3),
format, format,
StorableVecGeneatorOptions::default().add_last() computation,
EagerVecBuilderOptions::default().add_last()
) )
.unwrap() .unwrap()
}), }),
@@ -944,10 +993,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap"), &suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap"),
true, Source::Compute,
version + VERSION + Version::new(3), version + VERSION + Version::new(3),
format, format,
StorableVecGeneatorOptions::default().add_last() computation,
EagerVecBuilderOptions::default().add_last()
) )
.unwrap() .unwrap()
}), }),
@@ -955,10 +1005,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import( ComputedVecsFromDateIndex::forced_import(
path, path,
&suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap"), &suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap"),
true, Source::Compute,
version + VERSION + Version::new(3), version + VERSION + Version::new(3),
format, format,
StorableVecGeneatorOptions::default().add_last() computation,
EagerVecBuilderOptions::default().add_last()
) )
.unwrap() .unwrap()
}), }),
+96 -73
View File
@@ -18,7 +18,7 @@ use crate::{
BlockState, SupplyState, Transacted, BlockState, SupplyState, Transacted,
stores::Stores, stores::Stores,
vecs::{ vecs::{
grouped::ComputedVecsFromHeight, grouped::{ComputedVecsFromHeight, Source},
market, market,
stateful::{ stateful::{
addresstype_to_addresscount::AddressTypeToAddressCount, addresstype_to_addresscount::AddressTypeToAddressCount,
@@ -31,7 +31,7 @@ use crate::{
use super::{ use super::{
Indexes, fetched, Indexes, fetched,
grouped::{ComputedValueVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedValueVecsFromHeight, EagerVecBuilderOptions},
indexes, transactions, indexes, transactions,
}; };
@@ -78,7 +78,7 @@ impl Vecs {
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
version: Version, version: Version,
_computation: Computation, computation: Computation,
format: Format, format: Format,
fetched: Option<&fetched::Vecs>, fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
@@ -106,10 +106,11 @@ impl Vecs {
indexes_to_unspendable_supply: ComputedValueVecsFromHeight::forced_import( indexes_to_unspendable_supply: ComputedValueVecsFromHeight::forced_import(
path, path,
"unspendable_supply", "unspendable_supply",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
)?, )?,
height_to_opreturn_supply: EagerVec::forced_import( height_to_opreturn_supply: EagerVec::forced_import(
@@ -121,27 +122,30 @@ impl Vecs {
indexes_to_opreturn_supply: ComputedValueVecsFromHeight::forced_import( indexes_to_opreturn_supply: ComputedValueVecsFromHeight::forced_import(
path, path,
"opreturn_supply", "opreturn_supply",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars, compute_dollars,
)?, )?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import( indexes_to_address_count: ComputedVecsFromHeight::forced_import(
path, path,
"address_count", "address_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import( indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import(
path, path,
"empty_address_count", "empty_address_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from( addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from(
ByAddressType { ByAddressType {
@@ -252,66 +256,74 @@ impl Vecs {
p2pk65: ComputedVecsFromHeight::forced_import( p2pk65: ComputedVecsFromHeight::forced_import(
path, path,
"p2pk65_address_count", "p2pk65_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2pk33: ComputedVecsFromHeight::forced_import( p2pk33: ComputedVecsFromHeight::forced_import(
path, path,
"p2pk33_address_count", "p2pk33_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2pkh: ComputedVecsFromHeight::forced_import( p2pkh: ComputedVecsFromHeight::forced_import(
path, path,
"p2pkh_address_count", "p2pkh_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2sh: ComputedVecsFromHeight::forced_import( p2sh: ComputedVecsFromHeight::forced_import(
path, path,
"p2sh_address_count", "p2sh_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2wpkh: ComputedVecsFromHeight::forced_import( p2wpkh: ComputedVecsFromHeight::forced_import(
path, path,
"p2wpkh_address_count", "p2wpkh_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2wsh: ComputedVecsFromHeight::forced_import( p2wsh: ComputedVecsFromHeight::forced_import(
path, path,
"p2wsh_address_count", "p2wsh_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2tr: ComputedVecsFromHeight::forced_import( p2tr: ComputedVecsFromHeight::forced_import(
path, path,
"p2tr_address_count", "p2tr_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2a: ComputedVecsFromHeight::forced_import( p2a: ComputedVecsFromHeight::forced_import(
path, path,
"p2a_address_count", "p2a_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
}, },
), ),
@@ -320,73 +332,81 @@ impl Vecs {
p2pk65: ComputedVecsFromHeight::forced_import( p2pk65: ComputedVecsFromHeight::forced_import(
path, path,
"p2pk65_empty_address_count", "p2pk65_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2pk33: ComputedVecsFromHeight::forced_import( p2pk33: ComputedVecsFromHeight::forced_import(
path, path,
"p2pk33_empty_address_count", "p2pk33_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2pkh: ComputedVecsFromHeight::forced_import( p2pkh: ComputedVecsFromHeight::forced_import(
path, path,
"p2pkh_empty_address_count", "p2pkh_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2sh: ComputedVecsFromHeight::forced_import( p2sh: ComputedVecsFromHeight::forced_import(
path, path,
"p2sh_empty_address_count", "p2sh_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2wpkh: ComputedVecsFromHeight::forced_import( p2wpkh: ComputedVecsFromHeight::forced_import(
path, path,
"p2wpkh_empty_address_count", "p2wpkh_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2wsh: ComputedVecsFromHeight::forced_import( p2wsh: ComputedVecsFromHeight::forced_import(
path, path,
"p2wsh_empty_address_count", "p2wsh_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2tr: ComputedVecsFromHeight::forced_import( p2tr: ComputedVecsFromHeight::forced_import(
path, path,
"p2tr_empty_address_count", "p2tr_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
p2a: ComputedVecsFromHeight::forced_import( p2a: ComputedVecsFromHeight::forced_import(
path, path,
"p2a_empty_address_count", "p2a_empty_address_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
}, },
), ),
utxo_vecs: utxo_cohorts::Vecs::forced_import( utxo_vecs: utxo_cohorts::Vecs::forced_import(
path, path,
version, version,
_computation, computation,
format, format,
fetched, fetched,
&states_path, &states_path,
@@ -394,7 +414,7 @@ impl Vecs {
address_vecs: address_cohorts::Vecs::forced_import( address_vecs: address_cohorts::Vecs::forced_import(
path, path,
version, version,
_computation, computation,
format, format,
fetched, fetched,
&states_path, &states_path,
@@ -1302,34 +1322,37 @@ impl Vecs {
// Capped as external drives (even thunderbolt 4 SSDs) can be overwhelmed // Capped as external drives (even thunderbolt 4 SSDs) can be overwhelmed
let chunk_size = (vecs.len() as f64 / 3.0).ceil() as usize; let chunk_size = (vecs.len() as f64 / 3.0).ceil() as usize;
vecs.into_par_iter().chunks(chunk_size).try_for_each(|v| { vecs.into_par_iter()
v.into_iter().try_for_each(|either| match either { // .into_iter()
Either::Left(v) => v.compute_rest_part2( .chunks(chunk_size)
indexer, .try_for_each(|v| {
indexes, v.into_iter().try_for_each(|either| match either {
fetched, Either::Left(v) => v.compute_rest_part2(
starting_indexes, indexer,
market, indexes,
&height_to_supply, fetched,
dateindex_to_supply_ref, starting_indexes,
height_to_realized_cap_ref, market,
dateindex_to_realized_cap_ref, &height_to_supply,
exit, dateindex_to_supply_ref,
), height_to_realized_cap_ref,
Either::Right(v) => v.compute_rest_part2( dateindex_to_realized_cap_ref,
indexer, exit,
indexes, ),
fetched, Either::Right(v) => v.compute_rest_part2(
starting_indexes, indexer,
market, indexes,
&height_to_supply, fetched,
dateindex_to_supply_ref, starting_indexes,
height_to_realized_cap_ref, market,
dateindex_to_realized_cap_ref, &height_to_supply,
exit, dateindex_to_supply_ref,
), height_to_realized_cap_ref,
}) dateindex_to_realized_cap_ref,
})?; exit,
),
})
})?;
self.indexes_to_unspendable_supply.compute_rest( self.indexes_to_unspendable_supply.compute_rest(
indexer, indexer,
+84 -63
View File
@@ -11,11 +11,13 @@ use brk_vec::{
ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, Format, StoredIndex, VecIterator, ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, Format, StoredIndex, VecIterator,
}; };
use crate::vecs::grouped::Source;
use super::{ use super::{
Indexes, fetched, Indexes, fetched,
grouped::{ grouped::{
ComputedValueVecsFromHeight, ComputedValueVecsFromTxindex, ComputedVecsFromHeight, ComputedValueVecsFromHeight, ComputedValueVecsFromTxindex, ComputedVecsFromHeight,
ComputedVecsFromTxindex, StorableVecGeneatorOptions, ComputedVecsFromTxindex, EagerVecBuilderOptions,
}, },
indexes, indexes,
}; };
@@ -237,7 +239,8 @@ impl Vecs {
// true, // true,
// version + VERSION + Version::ZERO, // version + VERSION + Version::ZERO,
// format, // format,
// StorableVecGeneatorOptions::default() // computation,
// StorableVecGeneatorOptions::default()
// .add_average() // .add_average()
// .add_sum() // .add_sum()
// .add_cumulative(), // .add_cumulative(),
@@ -286,7 +289,8 @@ impl Vecs {
// true, // true,
// version + VERSION + Version::ZERO, // version + VERSION + Version::ZERO,
// format, // format,
// StorableVecGeneatorOptions::default() // computation,
// StorableVecGeneatorOptions::default()
// .add_average() // .add_average()
// .add_sum() // .add_sum()
// .add_cumulative(), // .add_cumulative(),
@@ -339,10 +343,11 @@ impl Vecs {
indexes_to_tx_count: ComputedVecsFromHeight::forced_import( indexes_to_tx_count: ComputedVecsFromHeight::forced_import(
path, path,
"tx_count", "tx_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -352,10 +357,11 @@ impl Vecs {
indexes_to_input_count: ComputedVecsFromTxindex::forced_import( indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
path, path,
"input_count", "input_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -365,10 +371,11 @@ impl Vecs {
indexes_to_output_count: ComputedVecsFromTxindex::forced_import( indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
path, path,
"output_count", "output_count",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -378,43 +385,40 @@ impl Vecs {
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import( indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
path, path,
"tx_v1", "tx_v1",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_tx_v2: ComputedVecsFromHeight::forced_import( indexes_to_tx_v2: ComputedVecsFromHeight::forced_import(
path, path,
"tx_v2", "tx_v2",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_tx_v3: ComputedVecsFromHeight::forced_import( indexes_to_tx_v3: ComputedVecsFromHeight::forced_import(
path, path,
"tx_v3", "tx_v3",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
)?, )?,
indexes_to_fee: ComputedValueVecsFromTxindex::forced_import( indexes_to_fee: ComputedValueVecsFromTxindex::forced_import(
path, path,
"fee", "fee",
indexes, indexes,
Some(txindex_to_fee.boxed_clone()), Source::Vec(txindex_to_fee.boxed_clone()),
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
computation, computation,
format, format,
fetched, fetched,
StorableVecGeneatorOptions::default() EagerVecBuilderOptions::default()
.add_sum() .add_sum()
.add_cumulative() .add_cumulative()
.add_percentiles() .add_percentiles()
@@ -424,10 +428,11 @@ impl Vecs {
indexes_to_feerate: ComputedVecsFromTxindex::forced_import( indexes_to_feerate: ComputedVecsFromTxindex::forced_import(
path, path,
"feerate", "feerate",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_percentiles() .add_percentiles()
.add_minmax() .add_minmax()
.add_average(), .add_average(),
@@ -435,10 +440,11 @@ impl Vecs {
indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import( indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import(
path, path,
"tx_vsize", "tx_vsize",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_percentiles() .add_percentiles()
.add_minmax() .add_minmax()
.add_average(), .add_average(),
@@ -446,10 +452,11 @@ impl Vecs {
indexes_to_tx_weight: ComputedVecsFromTxindex::forced_import( indexes_to_tx_weight: ComputedVecsFromTxindex::forced_import(
path, path,
"tx_weight", "tx_weight",
false, Source::None,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_percentiles() .add_percentiles()
.add_minmax() .add_minmax()
.add_average(), .add_average(),
@@ -457,10 +464,11 @@ impl Vecs {
indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import( indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import(
path, path,
"subsidy", "subsidy",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_percentiles() .add_percentiles()
.add_sum() .add_sum()
.add_cumulative() .add_cumulative()
@@ -471,10 +479,11 @@ impl Vecs {
indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import( indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import(
path, path,
"coinbase", "coinbase",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_sum() .add_sum()
.add_cumulative() .add_cumulative()
.add_percentiles() .add_percentiles()
@@ -485,21 +494,21 @@ impl Vecs {
indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight::forced_import( indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight::forced_import(
path, path,
"unclaimed_rewards", "unclaimed_rewards",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
.add_sum() EagerVecBuilderOptions::default().add_sum().add_cumulative(),
.add_cumulative(),
compute_dollars, compute_dollars,
)?, )?,
indexes_to_p2a_count: ComputedVecsFromHeight::forced_import( indexes_to_p2a_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2a_count", "p2a_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -509,10 +518,11 @@ impl Vecs {
indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import( indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2ms_count", "p2ms_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -522,10 +532,11 @@ impl Vecs {
indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import( indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2pk33_count", "p2pk33_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -535,10 +546,11 @@ impl Vecs {
indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import( indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2pk65_count", "p2pk65_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -548,10 +560,11 @@ impl Vecs {
indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import( indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2pkh_count", "p2pkh_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -561,10 +574,11 @@ impl Vecs {
indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import( indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2sh_count", "p2sh_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -574,10 +588,11 @@ impl Vecs {
indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import( indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2tr_count", "p2tr_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -587,10 +602,11 @@ impl Vecs {
indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import( indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2wpkh_count", "p2wpkh_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -600,10 +616,11 @@ impl Vecs {
indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import( indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import(
path, path,
"p2wsh_count", "p2wsh_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -613,10 +630,11 @@ impl Vecs {
indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import( indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import(
path, path,
"opreturn_count", "opreturn_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -626,10 +644,11 @@ impl Vecs {
indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import( indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import(
path, path,
"unknownoutput_count", "unknownoutput_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -639,10 +658,11 @@ impl Vecs {
indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import( indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import(
path, path,
"emptyoutput_count", "emptyoutput_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default() computation,
EagerVecBuilderOptions::default()
.add_average() .add_average()
.add_minmax() .add_minmax()
.add_percentiles() .add_percentiles()
@@ -652,10 +672,11 @@ impl Vecs {
indexes_to_exact_utxo_count: ComputedVecsFromHeight::forced_import( indexes_to_exact_utxo_count: ComputedVecsFromHeight::forced_import(
path, path,
"exact_utxo_count", "exact_utxo_count",
true, Source::Compute,
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
format, format,
StorableVecGeneatorOptions::default().add_last(), computation,
EagerVecBuilderOptions::default().add_last(),
)?, )?,
txindex_to_is_coinbase, txindex_to_is_coinbase,
inputindex_to_value, inputindex_to_value,
+7 -1
View File
@@ -1,6 +1,6 @@
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
ops::{Add, Div, Mul}, ops::{Add, AddAssign, Div, Mul},
}; };
use serde::Serialize; 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 { impl Mul for Bitcoin {
type Output = Self; type Output = Self;
fn mul(self, rhs: Self) -> Self::Output { fn mul(self, rhs: Self) -> Self::Output {
+4
View File
@@ -31,6 +31,10 @@ impl Date {
pub fn day(&self) -> u8 { pub fn day(&self) -> u8 {
(self.0 % 1_00) as u8 (self.0 % 1_00) as u8
} }
pub fn into_jiff(self) -> Date_ {
self.into()
}
} }
impl Default for Date { impl Default for Date {
+137 -2
View File
@@ -3,11 +3,14 @@ use std::{
ops::{Add, Rem}, ops::{Add, Rem},
}; };
use jiff::Span;
use serde::Serialize; use serde::Serialize;
// use color_eyre::eyre::eyre;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; 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; use super::Date;
@@ -103,3 +106,135 @@ impl Printable for DateIndex {
&["d", "date", "dateindex"] &["d", "date", "dateindex"]
} }
} }
impl FromCoarserIndex<WeekIndex> 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<MonthIndex> 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<QuarterIndex> 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<SemesterIndex> 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<YearIndex> 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<DecadeIndex> 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()
}
}
@@ -31,6 +31,18 @@ impl From<u8> for DecadeIndex {
} }
} }
impl From<DecadeIndex> for u8 {
fn from(value: DecadeIndex) -> Self {
value.0
}
}
impl From<DecadeIndex> for u16 {
fn from(value: DecadeIndex) -> Self {
value.0 as u16
}
}
impl From<usize> for DecadeIndex { impl From<usize> for DecadeIndex {
fn from(value: usize) -> Self { fn from(value: usize) -> Self {
Self(value as u8) Self(value as u8)
@@ -1,6 +1,6 @@
use std::{ use std::{
fmt::Debug, fmt::Debug,
ops::{Add, Div}, ops::{Add, AddAssign, Div},
}; };
use serde::{Deserialize, Serialize}; 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<usize> for DifficultyEpoch { impl Add<usize> for DifficultyEpoch {
type Output = Self; type Output = Self;
+7 -1
View File
@@ -1,6 +1,6 @@
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
ops::{Add, Div}, ops::{Add, AddAssign, Div},
}; };
use serde::Serialize; 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<usize> for Feerate { impl Div<usize> for Feerate {
type Output = Self; type Output = Self;
fn div(self, rhs: usize) -> Self::Output { fn div(self, rhs: usize) -> Self::Output {
+7 -1
View File
@@ -1,6 +1,6 @@
use std::{ use std::{
fmt::Debug, fmt::Debug,
ops::{Add, Div}, ops::{Add, AddAssign, Div},
}; };
use serde::{Deserialize, Serialize}; 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<usize> for HalvingEpoch { impl Add<usize> for HalvingEpoch {
type Output = Self; type Output = Self;
+2
View File
@@ -33,6 +33,7 @@ mod p2wshaddressindex;
mod quarterindex; mod quarterindex;
mod rawlocktime; mod rawlocktime;
mod sats; mod sats;
mod semesterindex;
mod stored_f32; mod stored_f32;
mod stored_f64; mod stored_f64;
mod stored_u32; mod stored_u32;
@@ -90,6 +91,7 @@ pub use p2wshaddressindex::*;
pub use quarterindex::*; pub use quarterindex::*;
pub use rawlocktime::*; pub use rawlocktime::*;
pub use sats::*; pub use sats::*;
pub use semesterindex::*;
pub use stored_f32::*; pub use stored_f32::*;
pub use stored_f64::*; pub use stored_f64::*;
pub use stored_u8::*; pub use stored_u8::*;
@@ -31,6 +31,12 @@ impl From<u16> for MonthIndex {
} }
} }
impl From<MonthIndex> for u16 {
fn from(value: MonthIndex) -> Self {
value.0
}
}
impl From<usize> for MonthIndex { impl From<usize> for MonthIndex {
fn from(value: usize) -> Self { fn from(value: usize) -> Self {
Self(value as u16) Self(value as u16)
+37 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use derive_deref::{Deref, DerefMut}; use derive_deref::{Deref, DerefMut};
use serde::{Serialize, Serializer, ser::SerializeTuple}; use serde::{Serialize, Serializer, ser::SerializeTuple};
@@ -236,6 +236,15 @@ where
} }
} }
impl<T> AddAssign for Open<T>
where
T: Add<Output = T> + Clone,
{
fn add_assign(&mut self, rhs: Self) {
**self = self.0.clone() + rhs.0
}
}
impl<T> Div<usize> for Open<T> impl<T> Div<usize> for Open<T>
where where
T: Div<usize, Output = T>, T: Div<usize, Output = T>,
@@ -324,6 +333,15 @@ where
} }
} }
impl<T> AddAssign for High<T>
where
T: Add<Output = T> + Clone,
{
fn add_assign(&mut self, rhs: Self) {
**self = self.0.clone() + rhs.0
}
}
impl<T> Div<usize> for High<T> impl<T> Div<usize> for High<T>
where where
T: Div<usize, Output = T>, T: Div<usize, Output = T>,
@@ -412,6 +430,15 @@ where
} }
} }
impl<T> AddAssign for Low<T>
where
T: Add<Output = T> + Clone,
{
fn add_assign(&mut self, rhs: Self) {
**self = self.0.clone() + rhs.0
}
}
impl<T> Div<usize> for Low<T> impl<T> Div<usize> for Low<T>
where where
T: Div<usize, Output = T>, T: Div<usize, Output = T>,
@@ -515,6 +542,15 @@ where
} }
} }
impl<T> AddAssign for Close<T>
where
T: Add<Output = T> + Clone,
{
fn add_assign(&mut self, rhs: Self) {
**self = self.0.clone() + rhs.0
}
}
impl<T> Div<usize> for Close<T> impl<T> Div<usize> for Close<T>
where where
T: Div<usize, Output = T>, T: Div<usize, Output = T>,
@@ -37,6 +37,12 @@ impl From<usize> for QuarterIndex {
} }
} }
impl From<QuarterIndex> for u16 {
fn from(value: QuarterIndex) -> Self {
value.0
}
}
impl From<QuarterIndex> for usize { impl From<QuarterIndex> for usize {
fn from(value: QuarterIndex) -> Self { fn from(value: QuarterIndex) -> Self {
value.0 as usize value.0 as usize
@@ -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<u16> for SemesterIndex {
fn from(value: u16) -> Self {
Self(value)
}
}
impl From<usize> for SemesterIndex {
fn from(value: usize) -> Self {
Self(value as u16)
}
}
impl From<SemesterIndex> for u16 {
fn from(value: SemesterIndex) -> Self {
value.0
}
}
impl From<SemesterIndex> for usize {
fn from(value: SemesterIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for SemesterIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self::from(self.0 + rhs as u16)
}
}
impl From<MonthIndex> 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> {
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"]
}
}
+7 -1
View File
@@ -1,7 +1,7 @@
use core::panic; use core::panic;
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
ops::{Add, Div, Mul, Sub}, ops::{Add, AddAssign, Div, Mul, Sub},
}; };
use derive_deref::Deref; 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<StoredF32> for f32 { impl From<StoredF32> for f32 {
fn from(value: StoredF32) -> Self { fn from(value: StoredF32) -> Self {
value.0 value.0
+7 -1
View File
@@ -1,7 +1,7 @@
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
f64, f64,
ops::{Add, Div, Mul}, ops::{Add, AddAssign, Div, Mul},
}; };
use derive_deref::Deref; 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<StoredF64> for f64 { impl From<StoredF64> for f64 {
fn from(value: StoredF64) -> Self { fn from(value: StoredF64) -> Self {
value.0 value.0
+7 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref; use derive_deref::Deref;
use serde::Serialize; 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<f64> for StoredU32 { impl From<f64> for StoredU32 {
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 { if value < 0.0 || value > u32::MAX as f64 {
+7 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref; use derive_deref::Deref;
use serde::Serialize; 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<f64> for StoredU64 { impl From<f64> for StoredU64 {
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 { if value < 0.0 || value > u32::MAX as f64 {
+7 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref; use derive_deref::Deref;
use serde::Serialize; 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<f64> for StoredU8 { impl From<f64> for StoredU8 {
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 { if value < 0.0 || value > u32::MAX as f64 {
+7 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use derive_deref::{Deref, DerefMut}; use derive_deref::{Deref, DerefMut};
use serde::Serialize; 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<f64> for StoredUsize { impl From<f64> for StoredUsize {
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 { if value < 0.0 || value > u32::MAX as f64 {
+7 -1
View File
@@ -1,6 +1,6 @@
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
ops::{Add, Div}, ops::{Add, AddAssign, Div},
}; };
use derive_deref::Deref; 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<f64> for Timestamp { impl From<f64> for Timestamp {
fn from(value: f64) -> Self { fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 { if value < 0.0 || value > u32::MAX as f64 {
+6
View File
@@ -65,6 +65,12 @@ impl Version {
} }
} }
impl From<Version> for u64 {
fn from(value: Version) -> u64 {
value.0
}
}
impl From<u64> for Version { impl From<u64> for Version {
fn from(value: u64) -> Self { fn from(value: u64) -> Self {
Self(value) Self(value)
+6 -1
View File
@@ -31,6 +31,12 @@ impl From<u16> for WeekIndex {
} }
} }
impl From<WeekIndex> for u16 {
fn from(value: WeekIndex) -> Self {
value.0
}
}
impl From<usize> for WeekIndex { impl From<usize> for WeekIndex {
fn from(value: usize) -> Self { fn from(value: usize) -> Self {
Self(value as u16) Self(value as u16)
@@ -68,7 +74,6 @@ impl From<Date> for WeekIndex {
let d = jiff::civil::Date::new(year, 6, 6).unwrap(); let d = jiff::civil::Date::new(year, 6, 6).unwrap();
let i = d.iso_week_date(); let i = d.iso_week_date();
let w = i.weeks_in_year(); let w = i.weeks_in_year();
// dbg!(d, w);
week += w as u16; week += w as u16;
year += 1; year += 1;
} }
+7 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div}; use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref; use derive_deref::Deref;
use serde::Serialize; 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<usize> for Weight { impl Div<usize> for Weight {
type Output = Self; type Output = Self;
fn div(self, rhs: usize) -> Self::Output { fn div(self, rhs: usize) -> Self::Output {
@@ -0,0 +1,12 @@
use std::ops::RangeInclusive;
pub trait FromCoarserIndex<T> {
fn min_from(coarser: T) -> usize;
fn max_from(coarser: T) -> usize;
fn inclusive_range_from(coarser: T) -> RangeInclusive<usize>
where
T: Clone,
{
Self::min_from(coarser.clone())..=Self::max_from(coarser)
}
}
+2
View File
@@ -1,3 +1,5 @@
mod from_coarser;
mod printable; mod printable;
pub use from_coarser::*;
pub use printable::*; pub use printable::*;
+1 -1
View File
@@ -7,7 +7,7 @@ pub fn setrlimit() -> io::Result<()> {
rlimit::setrlimit( rlimit::setrlimit(
Resource::NOFILE, Resource::NOFILE,
no_file_limit.0.max(210_000), no_file_limit.0.max(250_000),
no_file_limit.1, no_file_limit.1,
)?; )?;
+8 -3
View File
@@ -4,7 +4,8 @@ use brk_core::{
DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex, DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex,
MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex,
P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, 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 color_eyre::eyre::eyre;
use schemars::JsonSchema; use schemars::JsonSchema;
@@ -52,6 +53,8 @@ pub enum Index {
P2WSHAddressIndex, P2WSHAddressIndex,
#[schemars(description = "Quarter index")] #[schemars(description = "Quarter index")]
QuarterIndex, QuarterIndex,
#[schemars(description = "Semester index")]
SemesterIndex,
#[schemars(description = "Transaction index")] #[schemars(description = "Transaction index")]
TxIndex, TxIndex,
#[schemars(description = "Unknown output index")] #[schemars(description = "Unknown output index")]
@@ -63,7 +66,7 @@ pub enum Index {
} }
impl Index { impl Index {
pub fn all() -> [Self; 24] { pub fn all() -> [Self; 25] {
[ [
Self::DateIndex, Self::DateIndex,
Self::DecadeIndex, Self::DecadeIndex,
@@ -85,6 +88,7 @@ impl Index {
Self::P2WPKHAddressIndex, Self::P2WPKHAddressIndex,
Self::P2WSHAddressIndex, Self::P2WSHAddressIndex,
Self::QuarterIndex, Self::QuarterIndex,
Self::SemesterIndex,
Self::TxIndex, Self::TxIndex,
Self::UnknownOutputIndex, Self::UnknownOutputIndex,
Self::WeekIndex, Self::WeekIndex,
@@ -114,6 +118,7 @@ impl Index {
Self::P2WPKHAddressIndex => P2WPKHAddressIndex::to_possible_strings(), Self::P2WPKHAddressIndex => P2WPKHAddressIndex::to_possible_strings(),
Self::P2WSHAddressIndex => P2WSHAddressIndex::to_possible_strings(), Self::P2WSHAddressIndex => P2WSHAddressIndex::to_possible_strings(),
Self::QuarterIndex => QuarterIndex::to_possible_strings(), Self::QuarterIndex => QuarterIndex::to_possible_strings(),
Self::SemesterIndex => SemesterIndex::to_possible_strings(),
Self::TxIndex => TxIndex::to_possible_strings(), Self::TxIndex => TxIndex::to_possible_strings(),
Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(), Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(),
Self::WeekIndex => WeekIndex::to_possible_strings(), Self::WeekIndex => WeekIndex::to_possible_strings(),
@@ -174,7 +179,7 @@ impl TryFrom<&str> for Index {
Self::P2WSHAddressIndex 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::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::TxIndex).possible_values().contains(&v) => Self::TxIndex,
v if (Self::WeekIndex).possible_values().contains(&v) => Self::WeekIndex, v if (Self::WeekIndex).possible_values().contains(&v) => Self::WeekIndex,
v if (Self::YearIndex).possible_values().contains(&v) => Self::YearIndex, v if (Self::YearIndex).possible_values().contains(&v) => Self::YearIndex,
+6 -2
View File
@@ -6,9 +6,9 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use brk_computer::Computer; use brk_computer::Computer;
use brk_core::Result; use brk_core::{Height, Result};
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::AnyCollectableVec; use brk_vec::{AnyCollectableVec, AnyIndexedVec};
use tabled::settings::Style; use tabled::settings::Style;
mod deser; 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)> { pub fn search(&self, params: &Params) -> Vec<(String, &&dyn AnyCollectableVec)> {
let tuples = params let tuples = params
.ids .ids
+1 -1
View File
@@ -31,7 +31,7 @@ serde = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }
tower-http = { version = "0.6.6", features = ["compression-full", "trace"] } tower-http = { version = "0.6.6", features = ["compression-full", "trace"] }
tracing = "0.1.41" tracing = "0.1.41"
zip = "4.2.0" zip = "4.3.0"
[package.metadata.cargo-machete] [package.metadata.cargo-machete]
ignored = ["clap"] ignored = ["clap"]
+4 -1
View File
@@ -48,6 +48,8 @@ fn req_to_response_res(
let to = params.to(); let to = params.to();
let format = params.format(); let format = params.format();
// TODO: From and to should be capped here
let weight = vecs let weight = vecs
.iter() .iter()
.map(|(_, v)| v.range_weight(from, to)) .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}")); 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 if headers
.get_if_none_match() .get_if_none_match()
+5 -4
View File
@@ -1,4 +1,4 @@
use brk_core::Version; use brk_core::{Height, Version};
use super::{BoxedVecIterator, StoredIndex, StoredType}; use super::{BoxedVecIterator, StoredIndex, StoredType};
@@ -20,10 +20,10 @@ pub trait AnyVec: Send + Sync {
} }
fn index_type_to_string(&self) -> &'static str; fn index_type_to_string(&self) -> &'static str;
fn value_type_to_size_of(&self) -> usize; fn value_type_to_size_of(&self) -> usize;
fn etag(&self, to: Option<i64>) -> String { fn etag(&self, height: Height, to: Option<i64>) -> String {
let len = self.len(); let len = self.len();
format!( format!(
"{}-{:?}", "{}-{}-{}",
to.map_or(len, |to| { to.map_or(len, |to| {
if to.is_negative() { if to.is_negative() {
len.checked_sub(to.unsigned_abs() as usize) len.checked_sub(to.unsigned_abs() as usize)
@@ -32,7 +32,8 @@ pub trait AnyVec: Send + Sync {
to as usize to as usize
} }
}), }),
self.version() u64::from(self.version()),
u32::from(height),
) )
} }
+3 -2
View File
@@ -122,13 +122,14 @@ where
fn file_write_all(&mut self, file: &mut File, buf: &[u8]) -> Result<()> { fn file_write_all(&mut self, file: &mut File, buf: &[u8]) -> Result<()> {
file.write_all(buf)?; file.write_all(buf)?;
// file.flush()?;
// file.sync_data()?;
self.update_mmap(file) self.update_mmap(file)
} }
fn file_truncate_and_write_all(&mut self, file: &mut File, len: u64, buf: &[u8]) -> Result<()> { fn file_truncate_and_write_all(&mut self, file: &mut File, len: u64, buf: &[u8]) -> Result<()> {
Self::file_set_len_(file, len)?; Self::file_set_len_(file, len)?;
file.write_all(buf)?; self.file_write_all(file, buf)
self.update_mmap(file)
} }
fn reset(&mut self) -> Result<()>; fn reset(&mut self) -> Result<()>;
+6 -6
View File
@@ -92,7 +92,7 @@ where
S3T: StoredType, S3T: StoredType,
{ {
pub fn forced_import_or_init_from_1( pub fn forced_import_or_init_from_1(
mode: Computation, computation: Computation,
path: &Path, path: &Path,
name: &str, name: &str,
version: Version, version: Version,
@@ -100,7 +100,7 @@ where
source: BoxedAnyIterableVec<S1I, S1T>, source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>, compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Result<Self> { ) -> Result<Self> {
Ok(match mode { Ok(match computation {
Computation::Eager => Self::Eager { Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, name, version, format)?, vec: EagerVec::forced_import(path, name, version, format)?,
deps: Dependencies::From1(source, compute), deps: Dependencies::From1(source, compute),
@@ -114,7 +114,7 @@ where
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn forced_import_or_init_from_2( pub fn forced_import_or_init_from_2(
mode: Computation, computation: Computation,
path: &Path, path: &Path,
name: &str, name: &str,
version: Version, version: Version,
@@ -123,7 +123,7 @@ where
source2: BoxedAnyIterableVec<S2I, S2T>, source2: BoxedAnyIterableVec<S2I, S2T>,
compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>, compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>,
) -> Result<Self> { ) -> Result<Self> {
Ok(match mode { Ok(match computation {
Computation::Eager => Self::Eager { Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, name, version, format)?, vec: EagerVec::forced_import(path, name, version, format)?,
deps: Dependencies::From2((source1, source2), compute), deps: Dependencies::From2((source1, source2), compute),
@@ -137,7 +137,7 @@ where
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn forced_import_or_init_from_3( pub fn forced_import_or_init_from_3(
mode: Computation, computation: Computation,
path: &Path, path: &Path,
name: &str, name: &str,
version: Version, version: Version,
@@ -147,7 +147,7 @@ where
source3: BoxedAnyIterableVec<S3I, S3T>, source3: BoxedAnyIterableVec<S3I, S3T>,
compute: ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>, compute: ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
) -> Result<Self> { ) -> Result<Self> {
Ok(match mode { Ok(match computation {
Computation::Eager => Self::Eager { Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, name, version, format)?, vec: EagerVec::forced_import(path, name, version, format)?,
deps: Dependencies::From3((source1, source2, source3), compute), deps: Dependencies::From3((source1, source2, source3), compute),
-4
View File
@@ -35,10 +35,6 @@ where
source: BoxedAnyIterableVec<S1I, S1T>, source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>, compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Self { ) -> Self {
if source.index_type_to_string() != I::to_string() {
panic!("Should have same index");
}
Self { Self {
name: name.to_string(), name: name.to_string(),
version, version,
@@ -184,11 +184,13 @@ function createChartElement({
? 1 ? 1
: index === /** @satisfies {QuarterIndex} */ (19) : index === /** @satisfies {QuarterIndex} */ (19)
? 2 ? 2
: index === /** @satisfies {YearIndex} */ (23) : index === /** @satisfies {SemesterIndex} */ (20)
? 6 ? 3
: index === /** @satisfies {DecadeIndex} */ (1) : index === /** @satisfies {YearIndex} */ (24)
? 60 ? 6
: 0.5; : index === /** @satisfies {DecadeIndex} */ (1)
? 60
: 0.5;
ichart.applyOptions({ ichart.applyOptions({
timeScale: { timeScale: {
@@ -474,7 +476,8 @@ function createChartElement({
timeScaleSetCallback?.(() => { timeScaleSetCallback?.(() => {
if ( if (
index === /** @satisfies {QuarterIndex} */ (19) || index === /** @satisfies {QuarterIndex} */ (19) ||
index === /** @satisfies {YearIndex} */ (23) || index === /** @satisfies {SemesterIndex} */ (20) ||
index === /** @satisfies {YearIndex} */ (24) ||
index === /** @satisfies {DecadeIndex} */ (1) index === /** @satisfies {DecadeIndex} */ (1)
) { ) {
ichart.timeScale().setVisibleLogicalRange({ ichart.timeScale().setVisibleLogicalRange({
+7 -3
View File
@@ -7,7 +7,7 @@ const LINE = "line";
const CANDLE = "candle"; 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; break;
} }
default: { default: {
if (index === /** @satisfies {WeekIndex} */ (22)) { if (index === /** @satisfies {WeekIndex} */ (23)) {
date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7)); date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7));
} else if (index === /** @satisfies {MonthIndex} */ (7)) { } else if (index === /** @satisfies {MonthIndex} */ (7)) {
date.setUTCDate(1); date.setUTCDate(1);
} else if (index === /** @satisfies {QuarterIndex} */ (19)) { } else if (index === /** @satisfies {QuarterIndex} */ (19)) {
const month = date.getUTCMonth(); const month = date.getUTCMonth();
date.setUTCMonth(month - (month % 3), 1); 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); date.setUTCMonth(0, 1);
} else if (index === /** @satisfies {DecadeIndex} */ (1)) { } else if (index === /** @satisfies {DecadeIndex} */ (1)) {
date.setUTCFullYear( date.setUTCFullYear(
@@ -465,6 +468,7 @@ function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
"d.epoch", "d.epoch",
"month", "month",
"quarter", "quarter",
"semester",
"year", "year",
// "halving epoch", // "halving epoch",
"decade", "decade",
+15 -9
View File
@@ -6,7 +6,7 @@
* @import * as _ from "../packages/ufuzzy/v1.0.18/types" * @import * as _ from "../packages/ufuzzy/v1.0.18/types"
* @import { SerializedChartableIndex } from "./chart"; * @import { SerializedChartableIndex } from "./chart";
* @import { Signal, Signals, Accessor } from "../packages/solid-signals/wrapper"; * @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"; return "p2wshaddressindex";
case /** @satisfies {QuarterIndex} */ (19): case /** @satisfies {QuarterIndex} */ (19):
return "quarterindex"; return "quarterindex";
case /** @satisfies {TxIndex} */ (20): case /** @satisfies {SemesterIndex} */ (20):
return "semesterindex";
case /** @satisfies {TxIndex} */ (21):
return "txindex"; return "txindex";
case /** @satisfies {UnknownOutputIndex} */ (21): case /** @satisfies {UnknownOutputIndex} */ (22):
return "unknownoutputindex"; return "unknownoutputindex";
case /** @satisfies {WeekIndex} */ (22): case /** @satisfies {WeekIndex} */ (23):
return "weekindex"; return "weekindex";
case /** @satisfies {YearIndex} */ (23): case /** @satisfies {YearIndex} */ (24):
return "yearindex"; return "yearindex";
} }
}, },
@@ -1196,9 +1198,11 @@ function createUtils() {
return "month"; return "month";
case /** @satisfies {QuarterIndex} */ (19): case /** @satisfies {QuarterIndex} */ (19):
return "quarter"; return "quarter";
case /** @satisfies {WeekIndex} */ (22): case /** @satisfies {SemesterIndex} */ (20):
return "semester";
case /** @satisfies {WeekIndex} */ (23):
return "week"; return "week";
case /** @satisfies {YearIndex} */ (23): case /** @satisfies {YearIndex} */ (24):
return "year"; return "year";
default: default:
return null; return null;
@@ -1215,15 +1219,17 @@ function createUtils() {
case "date": case "date":
return /** @satisfies {DateIndex} */ (0); return /** @satisfies {DateIndex} */ (0);
case "week": case "week":
return /** @satisfies {WeekIndex} */ (22); return /** @satisfies {WeekIndex} */ (23);
case "d.epoch": case "d.epoch":
return /** @satisfies {DifficultyEpoch} */ (2); return /** @satisfies {DifficultyEpoch} */ (2);
case "month": case "month":
return /** @satisfies {MonthIndex} */ (7); return /** @satisfies {MonthIndex} */ (7);
case "quarter": case "quarter":
return /** @satisfies {QuarterIndex} */ (19); return /** @satisfies {QuarterIndex} */ (19);
case "semester":
return /** @satisfies {SemesterIndex} */ (20);
case "year": case "year":
return /** @satisfies {YearIndex} */ (23); return /** @satisfies {YearIndex} */ (24);
case "decade": case "decade":
return /** @satisfies {DecadeIndex} */ (1); return /** @satisfies {DecadeIndex} */ (1);
default: default:
+7 -4
View File
@@ -406,6 +406,7 @@ function createSerializedIndexes() {
/** @satisfies {VecId} */ ("inputindex"), /** @satisfies {VecId} */ ("inputindex"),
/** @satisfies {VecId} */ ("monthindex"), /** @satisfies {VecId} */ ("monthindex"),
/** @satisfies {VecId} */ ("opreturnindex"), /** @satisfies {VecId} */ ("opreturnindex"),
/** @satisfies {VecId} */ ("semesterindex"),
/** @satisfies {VecId} */ ("outputindex"), /** @satisfies {VecId} */ ("outputindex"),
/** @satisfies {VecId} */ ("p2aaddressindex"), /** @satisfies {VecId} */ ("p2aaddressindex"),
/** @satisfies {VecId} */ ("p2msoutputindex"), /** @satisfies {VecId} */ ("p2msoutputindex"),
@@ -437,21 +438,23 @@ function serializedIndexToIndex(serializedIndex) {
case "dateindex": case "dateindex":
return /** @satisfies {DateIndex} */ (0); return /** @satisfies {DateIndex} */ (0);
case "weekindex": case "weekindex":
return /** @satisfies {WeekIndex} */ (22); return /** @satisfies {WeekIndex} */ (23);
case "difficultyepoch": case "difficultyepoch":
return /** @satisfies {DifficultyEpoch} */ (2); return /** @satisfies {DifficultyEpoch} */ (2);
case "monthindex": case "monthindex":
return /** @satisfies {MonthIndex} */ (7); return /** @satisfies {MonthIndex} */ (7);
case "quarterindex": case "quarterindex":
return /** @satisfies {QuarterIndex} */ (19); return /** @satisfies {QuarterIndex} */ (19);
case "semesterindex":
return /** @satisfies {SemesterIndex} */ (20);
case "yearindex": case "yearindex":
return /** @satisfies {YearIndex} */ (23); return /** @satisfies {YearIndex} */ (24);
case "decadeindex": case "decadeindex":
return /** @satisfies {DecadeIndex} */ (1); return /** @satisfies {DecadeIndex} */ (1);
case "halvingepoch": case "halvingepoch":
return /** @satisfies {HalvingEpoch} */ (4); return /** @satisfies {HalvingEpoch} */ (4);
case "txindex": case "txindex":
return /** @satisfies {TxIndex} */ (20); return /** @satisfies {TxIndex} */ (21);
case "inputindex": case "inputindex":
return /** @satisfies {InputIndex} */ (6); return /** @satisfies {InputIndex} */ (6);
case "outputindex": case "outputindex":
@@ -479,7 +482,7 @@ function serializedIndexToIndex(serializedIndex) {
case "emptyoutputindex": case "emptyoutputindex":
return /** @satisfies {EmptyOutputIndex} */ (3); return /** @satisfies {EmptyOutputIndex} */ (3);
case "unknownoutputindex": case "unknownoutputindex":
return /** @satisfies {UnknownOutputIndex} */ (21); return /** @satisfies {UnknownOutputIndex} */ (22);
} }
} }