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

47
Cargo.lock generated
View File

@@ -1150,21 +1150,11 @@ checksum = "6236364b88b9b6d0bc181ba374cf1ab55ba3ef97a1cb6f8cddad48a273767fb5"
[[package]]
name = "bzip2"
version = "0.5.2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
checksum = "bea8dcd42434048e4f7a304411d9273a411f647446c1234a65ce0554923f4cff"
dependencies = [
"bzip2-sys",
]
[[package]]
name = "bzip2-sys"
version = "0.1.13+1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
dependencies = [
"cc",
"pkg-config",
"libbz2-rs-sys",
]
[[package]]
@@ -1237,18 +1227,18 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.40"
version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f"
checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.40"
version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e"
checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d"
dependencies = [
"anstream",
"anstyle",
@@ -1258,9 +1248,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.5.40"
version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce"
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
dependencies = [
"heck",
"proc-macro2",
@@ -1912,11 +1902,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"r-efi",
"wasi 0.14.2+wasi-0.2.4",
"wasm-bindgen",
]
[[package]]
@@ -2316,6 +2304,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libbz2-rs-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "775bf80d5878ab7c2b1080b5351a48b2f737d9f6f8b383574eebcc22be0dfccb"
[[package]]
name = "libc"
version = "0.2.174"
@@ -3318,6 +3312,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppmd-rust"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c834641d8ad1b348c9ee86dec3b9840d805acd5f24daa5f90c788951a52ff59b"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
@@ -4996,9 +4996,9 @@ dependencies = [
[[package]]
name = "zip"
version = "4.2.0"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ab361742de920c5535880f89bbd611ee62002bf11341d16a5f057bb8ba6899"
checksum = "9aed4ac33e8eb078c89e6cbb1d5c4c7703ec6d299fc3e7c3695af8f8b423468b"
dependencies = [
"aes",
"arbitrary",
@@ -5013,6 +5013,7 @@ dependencies = [
"liblzma",
"memchr",
"pbkdf2",
"ppmd-rust",
"sha1",
"time",
"zeroize",

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_vec = { version = "0.0.76", path = "crates/brk_vec" }
byteview = "=0.6.1"
clap = { version = "4.5.40", features = ["string"] }
clap_derive = "4.5.40"
clap = { version = "4.5.41", features = ["string"] }
clap_derive = "4.5.41"
color-eyre = "0.6.5"
derive_deref = "1.1.1"
fjall = "2.11.1"

View File

@@ -17,14 +17,19 @@
- add address counts relative to all datasets
- make decade, quarter, year datasets `computed` instead of `eager`
- add 6 months (semester) interval datasets to builder
- some datasets in `indexes` can probably be removed
- add revived/sent supply datasets
- add `in-sats` version of all price datasets (average and co)
- add `p2pk` group (sum of `p2pk33` and `p2pk65`)
- add chopiness datasets
- add utxo count, address count, supply data for by reused addresses in groups by address type
- add more date ranges (3-6 months and more)
- add puell multiple dataset
- add pi cycle dataset
- add ema of price
- add emas of price
- add 7d and 30d ema to sell side risk ratio and sopr
- don't compute everything for all cohorts as some datasets combinations are irrelevant
- addresses/utxos by amount don't need mvrvz for example
- add all possible charts from:
- https://mainnet.observer
- https://glassnode.com
@@ -73,6 +78,7 @@
- remove `sum` series when it's a duplicate of the `base` (in subsidy for example)
- selected unit sometimes changes when going back end forth
- add support for custom charts
- separate z-score charts from "realized price" (with their own prices), have 4y, 2y and 1y
- price scale format depends on unit, hide digits for sats for example (if/when possible)
- table
- pagination

View File

@@ -8,9 +8,11 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format};
use crate::vecs::grouped::Source;
use super::{
Indexes,
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes,
};
@@ -34,7 +36,7 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
) -> color_eyre::Result<Self> {
Ok(Self {
@@ -47,18 +49,20 @@ impl Vecs {
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
path,
"timestamp",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
computation,
EagerVecBuilderOptions::default().add_first(),
)?,
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
path,
"block_interval",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -66,32 +70,29 @@ impl Vecs {
indexes_to_block_count: ComputedVecsFromHeight::forced_import(
path,
"block_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_block_weight: ComputedVecsFromHeight::forced_import(
path,
"block_weight",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
path,
"block_size",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
height_to_vbytes: EagerVec::forced_import(
path,
@@ -102,12 +103,11 @@ impl Vecs {
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
path,
"block_vbytes",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
difficultyepoch_to_timestamp: EagerVec::forced_import(
path,

View File

@@ -7,13 +7,13 @@ use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
use crate::vecs::{
fetched,
grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight},
grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, Source},
stateful, transactions,
};
use super::{
Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes,
};
@@ -51,7 +51,7 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> {
@@ -61,194 +61,207 @@ impl Vecs {
indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import(
path,
"coinblocks_created",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_coinblocks_stored: ComputedVecsFromHeight::forced_import(
path,
"coinblocks_stored",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_liveliness: ComputedVecsFromHeight::forced_import(
path,
"liveliness",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_vaultedness: ComputedVecsFromHeight::forced_import(
path,
"vaultedness",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight::forced_import(
path,
"activity_to_vaultedness_ratio",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_supply: ComputedValueVecsFromHeight::forced_import(
path,
"vaulted_supply",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)?,
indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import(
path,
"active_supply",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)?,
indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import(
path,
"thermo_cap",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_investor_cap: ComputedVecsFromHeight::forced_import(
path,
"investor_cap",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_cap: ComputedVecsFromHeight::forced_import(
path,
"vaulted_cap",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_active_cap: ComputedVecsFromHeight::forced_import(
path,
"active_cap",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_price: ComputedVecsFromHeight::forced_import(
path,
"vaulted_price",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"vaulted_price",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
)?,
indexes_to_active_price: ComputedVecsFromHeight::forced_import(
path,
"active_price",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"active_price",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
)?,
indexes_to_true_market_mean: ComputedVecsFromHeight::forced_import(
path,
"true_market_mean",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_true_market_mean_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"true_market_mean",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
)?,
indexes_to_cointime_value_destroyed: ComputedVecsFromHeight::forced_import(
path,
"cointime_value_destroyed",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_cointime_value_created: ComputedVecsFromHeight::forced_import(
path,
"cointime_value_created",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_cointime_value_stored: ComputedVecsFromHeight::forced_import(
path,
"cointime_value_stored",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_cointime_price: ComputedVecsFromHeight::forced_import(
path,
"cointime_price",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_cointime_cap: ComputedVecsFromHeight::forced_import(
path,
"cointime_cap",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"cointime_price",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
)?,
})
}

View File

@@ -5,9 +5,11 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyVec, Computation, Format};
use crate::vecs::grouped::Source;
use super::{
Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes,
};
@@ -25,41 +27,45 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
) -> color_eyre::Result<Self> {
Ok(Self {
constant_0: ComputedVecsFromHeight::forced_import(
path,
"constant_0",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
constant_1: ComputedVecsFromHeight::forced_import(
path,
"constant_1",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
constant_50: ComputedVecsFromHeight::forced_import(
path,
"constant_50",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
constant_100: ComputedVecsFromHeight::forced_import(
path,
"constant_100",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
})
}

View File

@@ -2,18 +2,19 @@ use std::path::Path;
use brk_core::{
Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex,
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, Version, WeekIndex, YearIndex,
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, SemesterIndex, Version, WeekIndex,
YearIndex,
};
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format, StoredIndex};
use crate::vecs::grouped::Source;
use super::{
Indexes,
grouped::{
ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, StorableVecGeneatorOptions,
},
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, EagerVecBuilderOptions},
indexes,
};
@@ -57,6 +58,8 @@ pub struct Vecs {
pub monthindex_to_ohlc_in_sats: EagerVec<MonthIndex, OHLCSats>,
pub quarterindex_to_ohlc: EagerVec<QuarterIndex, OHLCDollars>,
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_in_sats: EagerVec<YearIndex, OHLCSats>,
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
@@ -72,7 +75,7 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
) -> color_eyre::Result<Self> {
let mut fetched_path = path.to_owned();
@@ -167,122 +170,130 @@ impl Vecs {
timeindexes_to_open: ComputedVecsFromDateIndex::forced_import(
path,
"open",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
computation,
EagerVecBuilderOptions::default().add_first(),
)?,
timeindexes_to_high: ComputedVecsFromDateIndex::forced_import(
path,
"high",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_max(),
computation,
EagerVecBuilderOptions::default().add_max(),
)?,
timeindexes_to_low: ComputedVecsFromDateIndex::forced_import(
path,
"low",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_min(),
computation,
EagerVecBuilderOptions::default().add_min(),
)?,
timeindexes_to_close: ComputedVecsFromDateIndex::forced_import(
path,
"close",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import(
path,
"open_in_sats",
true,
Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
computation,
EagerVecBuilderOptions::default().add_first(),
)?,
timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import(
path,
"high_in_sats",
true,
Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_max(),
computation,
EagerVecBuilderOptions::default().add_max(),
)?,
timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import(
path,
"low_in_sats",
true,
Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_min(),
computation,
EagerVecBuilderOptions::default().add_min(),
)?,
timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import(
path,
"close_in_sats",
true,
Source::Compute,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
path,
"open",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
EagerVecBuilderOptions::default().add_first(),
)?,
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
path,
"high",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_max(),
EagerVecBuilderOptions::default().add_max(),
)?,
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
path,
"low",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_min(),
EagerVecBuilderOptions::default().add_min(),
)?,
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
path,
"close",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
EagerVecBuilderOptions::default().add_last(),
)?,
chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"open_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
EagerVecBuilderOptions::default().add_first(),
)?,
chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"high_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_max(),
EagerVecBuilderOptions::default().add_max(),
)?,
chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"low_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_min(),
EagerVecBuilderOptions::default().add_min(),
)?,
chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"close_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
EagerVecBuilderOptions::default().add_last(),
)?,
weekindex_to_ohlc: EagerVec::forced_import(
path,
@@ -332,6 +343,18 @@ impl Vecs {
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
)?,
semesterindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
format,
)?,
semesterindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
format,
)?,
yearindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
@@ -693,6 +716,27 @@ impl Vecs {
exit,
)?;
let mut semesterindex_first_iter =
self.timeindexes_to_open.semesterindex.unwrap_first().iter();
let mut semesterindex_max_iter = self.timeindexes_to_high.semesterindex.unwrap_max().iter();
let mut semesterindex_min_iter = self.timeindexes_to_low.semesterindex.unwrap_min().iter();
self.semesterindex_to_ohlc.compute_transform(
starting_indexes.semesterindex,
self.timeindexes_to_close.semesterindex.unwrap_last(),
|(i, close, ..)| {
(
i,
OHLCDollars {
open: semesterindex_first_iter.unwrap_get_inner(i),
high: semesterindex_max_iter.unwrap_get_inner(i),
low: semesterindex_min_iter.unwrap_get_inner(i),
close,
},
)
},
exit,
)?;
let mut yearindex_first_iter = self.timeindexes_to_open.yearindex.unwrap_first().iter();
let mut yearindex_max_iter = self.timeindexes_to_high.yearindex.unwrap_max().iter();
let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter();
@@ -1044,6 +1088,40 @@ impl Vecs {
exit,
)?;
let mut semesterindex_first_iter = self
.timeindexes_to_open_in_sats
.semesterindex
.unwrap_first()
.iter();
let mut semesterindex_max_iter = self
.timeindexes_to_high_in_sats
.semesterindex
.unwrap_max()
.iter();
let mut semesterindex_min_iter = self
.timeindexes_to_low_in_sats
.semesterindex
.unwrap_min()
.iter();
self.semesterindex_to_ohlc_in_sats.compute_transform(
starting_indexes.semesterindex,
self.timeindexes_to_close_in_sats
.semesterindex
.unwrap_last(),
|(i, close, ..)| {
(
i,
OHLCSats {
open: semesterindex_first_iter.unwrap_get_inner(i),
high: semesterindex_max_iter.unwrap_get_inner(i),
low: semesterindex_min_iter.unwrap_get_inner(i),
close,
},
)
},
exit,
)?;
let mut yearindex_first_iter = self
.timeindexes_to_open_in_sats
.yearindex
@@ -1133,6 +1211,7 @@ impl Vecs {
&self.difficultyepoch_to_ohlc,
&self.monthindex_to_ohlc,
&self.quarterindex_to_ohlc,
&self.semesterindex_to_ohlc,
&self.yearindex_to_ohlc,
// &self.halvingepoch_to_ohlc,
&self.decadeindex_to_ohlc,
@@ -1142,6 +1221,7 @@ impl Vecs {
&self.difficultyepoch_to_ohlc_in_sats,
&self.monthindex_to_ohlc_in_sats,
&self.quarterindex_to_ohlc_in_sats,
&self.semesterindex_to_ohlc_in_sats,
&self.yearindex_to_ohlc_in_sats,
// &self.halvingepoch_to_ohlc_in_sats,
&self.decadeindex_to_ohlc_in_sats,

View File

@@ -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()
}
}
}

View File

@@ -10,7 +10,7 @@ use crate::utils::get_percentile;
use super::ComputedType;
#[derive(Clone, Debug)]
pub struct ComputedVecBuilder<I, T>
pub struct EagerVecBuilder<I, T>
where
I: StoredIndex,
T: ComputedType,
@@ -31,7 +31,7 @@ where
const VERSION: Version = Version::ZERO;
impl<I, T> ComputedVecBuilder<I, T>
impl<I, T> EagerVecBuilder<I, T>
where
I: StoredIndex,
T: ComputedType,
@@ -41,7 +41,7 @@ where
name: &str,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> {
let only_one_active = options.is_only_one_active();
@@ -384,7 +384,7 @@ where
pub fn from_aligned<I2>(
&mut self,
max_from: I,
source: &ComputedVecBuilder<I2, T>,
source: &EagerVecBuilder<I2, T>,
first_indexes: &impl AnyIterableVec<I, I2>,
count_indexes: &impl AnyIterableVec<I, StoredUsize>,
exit: &Exit,
@@ -706,7 +706,7 @@ where
}
#[derive(Default, Clone, Copy)]
pub struct StorableVecGeneatorOptions {
pub struct EagerVecBuilderOptions {
average: bool,
sum: bool,
max: bool,
@@ -721,7 +721,55 @@ pub struct StorableVecGeneatorOptions {
cumulative: bool,
}
impl StorableVecGeneatorOptions {
impl EagerVecBuilderOptions {
pub fn average(&self) -> bool {
self.average
}
pub fn sum(&self) -> bool {
self.sum
}
pub fn max(&self) -> bool {
self.max
}
pub fn _90p(&self) -> bool {
self._90p
}
pub fn _75p(&self) -> bool {
self._75p
}
pub fn median(&self) -> bool {
self.median
}
pub fn _25p(&self) -> bool {
self._25p
}
pub fn _10p(&self) -> bool {
self._10p
}
pub fn min(&self) -> bool {
self.min
}
pub fn first(&self) -> bool {
self.first
}
pub fn last(&self) -> bool {
self.last
}
pub fn cumulative(&self) -> bool {
self.cumulative
}
pub fn add_first(mut self) -> Self {
self.first = true;
self

View File

@@ -1,15 +1,18 @@
use std::path::Path;
use brk_core::{
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, Version, WeekIndex, YearIndex,
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, SemesterIndex, Version, WeekIndex,
YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format};
use brk_vec::{
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Computation, EagerVec, Format,
};
use crate::vecs::{Indexes, indexes};
use crate::vecs::{Indexes, grouped::ComputedVecBuilder, indexes};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions, Source};
#[derive(Clone)]
pub struct ComputedVecsFromDateIndex<T>
@@ -17,33 +20,35 @@ where
T: ComputedType + PartialOrd,
{
pub dateindex: Option<EagerVec<DateIndex, T>>,
pub dateindex_extra: ComputedVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
pub yearindex: ComputedVecBuilder<YearIndex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
pub dateindex_extra: EagerVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex>,
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex>,
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromDateIndex<T>
where
T: ComputedType,
T: ComputedType + 'static,
{
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<DateIndex, T>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
options: EagerVecBuilderOptions,
) -> 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()
});
let dateindex_extra = ComputedVecBuilder::forced_import(
let dateindex_extra = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -53,44 +58,71 @@ where
let options = options.remove_percentiles();
let dateindex_source = source.vec().or(dateindex.as_ref().map(|v| v.boxed_clone()));
Ok(Self {
dateindex,
dateindex_extra,
weekindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?,
semesterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
dateindex_source.clone(),
&dateindex_extra,
options.into(),
)?,
dateindex,
dateindex_extra,
})
}
@@ -133,65 +165,45 @@ where
if let Some(dateindex) = dateindex {
self.dateindex_extra
.extend(starting_indexes.dateindex, dateindex, exit)?;
self.weekindex.compute(
starting_indexes.weekindex,
dateindex,
&indexes.weekindex_to_first_dateindex,
&indexes.weekindex_to_dateindex_count,
exit,
)?;
self.monthindex.compute(
starting_indexes.monthindex,
dateindex,
&indexes.monthindex_to_first_dateindex,
&indexes.monthindex_to_dateindex_count,
exit,
)?;
} else {
let dateindex = self.dateindex.as_ref().unwrap();
self.dateindex_extra
.extend(starting_indexes.dateindex, dateindex, exit)?;
self.weekindex.compute(
starting_indexes.weekindex,
dateindex,
&indexes.weekindex_to_first_dateindex,
&indexes.weekindex_to_dateindex_count,
exit,
)?;
self.monthindex.compute(
starting_indexes.monthindex,
dateindex,
&indexes.monthindex_to_first_dateindex,
&indexes.monthindex_to_dateindex_count,
exit,
)?;
}
self.quarterindex.from_aligned(
self.weekindex.compute_if_necessary(
starting_indexes.weekindex,
&indexes.weekindex_to_dateindex_count,
exit,
)?;
self.monthindex.compute_if_necessary(
starting_indexes.monthindex,
&indexes.monthindex_to_dateindex_count,
exit,
)?;
self.quarterindex.compute_if_necessary(
starting_indexes.quarterindex,
&self.monthindex,
&indexes.quarterindex_to_first_monthindex,
&indexes.quarterindex_to_monthindex_count,
exit,
)?;
self.yearindex.from_aligned(
self.semesterindex.compute_if_necessary(
starting_indexes.semesterindex,
&indexes.semesterindex_to_monthindex_count,
exit,
)?;
self.yearindex.compute_if_necessary(
starting_indexes.yearindex,
&self.monthindex,
&indexes.yearindex_to_first_monthindex,
&indexes.yearindex_to_monthindex_count,
exit,
)?;
self.decadeindex.from_aligned(
self.decadeindex.compute_if_necessary(
starting_indexes.decadeindex,
&self.yearindex,
&indexes.decadeindex_to_first_yearindex,
&indexes.decadeindex_to_yearindex_count,
exit,
)?;
@@ -208,6 +220,7 @@ where
self.weekindex.vecs(),
self.monthindex.vecs(),
self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(),
self.decadeindex.vecs(),
]

View File

@@ -1,16 +1,20 @@
use std::path::Path;
use brk_core::{
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result, Version,
WeekIndex, YearIndex,
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result,
SemesterIndex, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format};
use crate::vecs::{Indexes, indexes};
use crate::vecs::{
Indexes,
grouped::{ComputedVecBuilder, Source},
indexes,
};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions};
#[derive(Clone)]
pub struct ComputedVecsFromHeight<T>
@@ -18,38 +22,39 @@ where
T: ComputedType + PartialOrd,
{
pub height: Option<EagerVec<Height, T>>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
// 6 months
pub yearindex: ComputedVecBuilder<YearIndex, T>,
pub height_extra: EagerVecBuilder<Height, T>,
pub dateindex: EagerVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex>,
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex>,
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromHeight<T>
where
T: ComputedType + Ord + From<f64>,
T: ComputedType + Ord + From<f64> + 'static,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<Height, T>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
options: EagerVecBuilderOptions,
) -> 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()
});
let height_extra = ComputedVecBuilder::forced_import(
let height_extra = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -57,7 +62,7 @@ where
options.copy_self_extra(),
)?;
let dateindex = ComputedVecBuilder::forced_import(
let dateindex = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -68,46 +73,71 @@ where
let options = options.remove_percentiles();
Ok(Self {
height,
height_extra,
dateindex,
weekindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?,
difficultyepoch: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
semesterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
computation,
None,
&dateindex,
options.into(),
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
computation,
None,
&dateindex,
options.into(),
)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
decadeindex: ComputedVecBuilder::forced_import(
height,
height_extra,
dateindex,
difficultyepoch: EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -189,42 +219,38 @@ where
)?;
}
self.weekindex.from_aligned(
self.weekindex.compute_if_necessary(
starting_indexes.weekindex,
&self.dateindex,
&indexes.weekindex_to_first_dateindex,
&indexes.weekindex_to_dateindex_count,
exit,
)?;
self.monthindex.from_aligned(
self.monthindex.compute_if_necessary(
starting_indexes.monthindex,
&self.dateindex,
&indexes.monthindex_to_first_dateindex,
&indexes.monthindex_to_dateindex_count,
exit,
)?;
self.quarterindex.from_aligned(
self.quarterindex.compute_if_necessary(
starting_indexes.quarterindex,
&self.monthindex,
&indexes.quarterindex_to_first_monthindex,
&indexes.quarterindex_to_monthindex_count,
exit,
)?;
self.yearindex.from_aligned(
self.semesterindex.compute_if_necessary(
starting_indexes.semesterindex,
&indexes.semesterindex_to_monthindex_count,
exit,
)?;
self.yearindex.compute_if_necessary(
starting_indexes.yearindex,
&self.monthindex,
&indexes.yearindex_to_first_monthindex,
&indexes.yearindex_to_monthindex_count,
exit,
)?;
self.decadeindex.from_aligned(
self.decadeindex.compute_if_necessary(
starting_indexes.decadeindex,
&self.yearindex,
&indexes.decadeindex_to_first_yearindex,
&indexes.decadeindex_to_yearindex_count,
exit,
)?;
@@ -243,6 +269,7 @@ where
self.difficultyepoch.vecs(),
self.monthindex.vecs(),
self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(),
// self.halvingepoch.vecs(),
self.decadeindex.vecs(),

View File

@@ -5,9 +5,9 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, EagerVec, Format};
use crate::vecs::{indexes, Indexes};
use crate::vecs::{Indexes, indexes};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions};
#[derive(Clone)]
pub struct ComputedVecsFromHeightStrict<T>
@@ -15,8 +15,8 @@ where
T: ComputedType + PartialOrd,
{
pub height: EagerVec<Height, T>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
pub height_extra: EagerVecBuilder<Height, T>,
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
}
@@ -32,12 +32,12 @@ where
name: &str,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> {
let height =
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)?;
let height_extra = ComputedVecBuilder::forced_import(
let height_extra = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -50,7 +50,7 @@ where
Ok(Self {
height,
height_extra,
difficultyepoch: ComputedVecBuilder::forced_import(
difficultyepoch: EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,

View File

@@ -2,17 +2,22 @@ use std::path::Path;
use brk_core::{
Bitcoin, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, MonthIndex, QuarterIndex,
Result, Sats, TxIndex, Version, WeekIndex, YearIndex,
Result, Sats, SemesterIndex, TxIndex, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex, VecIterator,
AnyCollectableVec, AnyVec, CollectableVec, Computation, EagerVec, Format, StoredIndex,
VecIterator,
};
use crate::vecs::{Indexes, fetched, indexes};
use crate::vecs::{
Indexes, fetched,
grouped::{ComputedVecBuilder, Source},
indexes,
};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
use super::{ComputedType, EagerVecBuilder, EagerVecBuilderOptions};
#[derive(Clone)]
pub struct ComputedVecsFromTxindex<T>
@@ -20,40 +25,42 @@ where
T: ComputedType + PartialOrd,
{
pub txindex: Option<Box<EagerVec<TxIndex, T>>>,
pub height: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
pub yearindex: ComputedVecBuilder<YearIndex, T>,
pub height: EagerVecBuilder<Height, T>,
pub dateindex: EagerVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex>,
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex>,
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromTxindex<T>
where
T: ComputedType + Ord + From<f64>,
T: ComputedType + Ord + From<f64> + 'static,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<TxIndex, T>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> {
let txindex = compute_source.then(|| {
let txindex = source.is_compute().then(|| {
Box::new(
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
.unwrap(),
)
});
let height = ComputedVecBuilder::forced_import(
let height = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -63,45 +70,80 @@ where
let options = options.remove_percentiles();
let dateindex = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?;
Ok(Self {
txindex,
height,
dateindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?,
weekindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?,
difficultyepoch: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
computation,
None,
&dateindex,
options.into(),
)?,
semesterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
computation,
None,
&dateindex,
options.into(),
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
computation,
None,
&dateindex,
options.into(),
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
computation,
None,
&dateindex,
options.into(),
)?,
txindex,
height,
dateindex,
difficultyepoch: EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -109,13 +151,6 @@ where
options,
)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
)?,
})
}
@@ -196,42 +231,38 @@ where
exit,
)?;
self.weekindex.from_aligned(
self.weekindex.compute_if_necessary(
starting_indexes.weekindex,
&self.dateindex,
&indexes.weekindex_to_first_dateindex,
&indexes.weekindex_to_dateindex_count,
exit,
)?;
self.monthindex.from_aligned(
self.monthindex.compute_if_necessary(
starting_indexes.monthindex,
&self.dateindex,
&indexes.monthindex_to_first_dateindex,
&indexes.monthindex_to_dateindex_count,
exit,
)?;
self.quarterindex.from_aligned(
self.quarterindex.compute_if_necessary(
starting_indexes.quarterindex,
&self.monthindex,
&indexes.quarterindex_to_first_monthindex,
&indexes.quarterindex_to_monthindex_count,
exit,
)?;
self.yearindex.from_aligned(
self.semesterindex.compute_if_necessary(
starting_indexes.semesterindex,
&indexes.semesterindex_to_monthindex_count,
exit,
)?;
self.yearindex.compute_if_necessary(
starting_indexes.yearindex,
&self.monthindex,
&indexes.yearindex_to_first_monthindex,
&indexes.yearindex_to_monthindex_count,
exit,
)?;
self.decadeindex.from_aligned(
self.decadeindex.compute_if_necessary(
starting_indexes.decadeindex,
&self.yearindex,
&indexes.decadeindex_to_first_yearindex,
&indexes.decadeindex_to_yearindex_count,
exit,
)?;
@@ -258,6 +289,7 @@ where
self.difficultyepoch.vecs(),
self.monthindex.vecs(),
self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(),
// self.halvingepoch.vecs(),
self.decadeindex.vecs(),

View File

@@ -1,21 +1,25 @@
mod builder;
mod builder_computed;
mod builder_eager;
mod from_dateindex;
mod from_height;
mod from_height_strict;
mod from_txindex;
mod ratio_from_dateindex;
mod source;
mod r#type;
mod value_from_dateindex;
mod value_from_height;
mod value_from_txindex;
mod value_height;
pub use builder::*;
pub use builder_computed::*;
pub use builder_eager::*;
pub use from_dateindex::*;
pub use from_height::*;
pub use from_height_strict::*;
pub use from_txindex::*;
pub use ratio_from_dateindex::*;
pub use source::*;
use r#type::*;
pub use value_from_dateindex::*;
pub use value_from_height::*;

View File

@@ -4,16 +4,16 @@ use brk_core::{Date, DateIndex, Dollars, Result, StoredF32, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex,
VecIterator,
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, Computation, EagerVec, Format,
StoredIndex, VecIterator,
};
use crate::{
utils::get_percentile,
vecs::{Indexes, fetched, indexes},
vecs::{Indexes, fetched, grouped::source::Source, indexes},
};
use super::{ComputedVecsFromDateIndex, StorableVecGeneatorOptions};
use super::{ComputedVecsFromDateIndex, EagerVecBuilderOptions};
#[derive(Clone)]
pub struct ComputedRatioVecsFromDateIndex {
@@ -64,20 +64,22 @@ impl ComputedRatioVecsFromDateIndex {
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<DateIndex, Dollars>,
version: Version,
format: Format,
computation: Computation,
) -> color_eyre::Result<Self> {
let options = StorableVecGeneatorOptions::default().add_last();
let options = EagerVecBuilderOptions::default().add_last();
Ok(Self {
price: compute_source.then(|| {
price: source.is_compute().then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
name,
true,
Source::Compute,
version + VERSION,
format,
computation,
options,
)
.unwrap()
@@ -85,297 +87,334 @@ impl ComputedRatioVecsFromDateIndex {
ratio: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_sma: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_sma"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_1w_sma: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_1w_sma"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_1m_sma: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_1m_sma"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_1y_sma: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_1y_sma"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_4y_sma: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_4y_sma"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_1y_sma_momentum_oscillator"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_4y_sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_4y_sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_1y_sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_1y_sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p99_9: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p99_9"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p99_5: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p99_5"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p99: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p99"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p1: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p1"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p0_5: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p0_5"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p0_1: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p0_1"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p1sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p1sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p2sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p2sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p3sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p3sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_m1sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_m1sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_m2sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_m2sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_m3sd: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_m3sd"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p99_9_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p99_9_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p99_5_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p99_5_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p99_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p99_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p1_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p1_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p0_5_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p0_5_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p0_1_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p0_1_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p1sd_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p1sd_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p2sd_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p2sd_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_p3sd_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_p3sd_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_m1sd_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_m1sd_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_m2sd_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_m2sd_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_m3sd_as_price: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_m3sd_as_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_zscore: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_zscore"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_4y_zscore: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_4y_zscore"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
ratio_1y_zscore: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_ratio_1y_zscore"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
computation,
options,
)?,
})

View File

@@ -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
}
}
}

View File

@@ -1,13 +1,14 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use brk_vec::StoredType;
pub trait ComputedType
where
Self: StoredType + From<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
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
{
}

View File

@@ -3,11 +3,11 @@ use std::path::Path;
use brk_core::{Bitcoin, DateIndex, Dollars, Result, Sats, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
use brk_vec::{AnyCollectableVec, CollectableVec, Computation, EagerVec, Format, StoredVec};
use crate::vecs::{Indexes, fetched, grouped::ComputedVecsFromDateIndex, indexes};
use super::StorableVecGeneatorOptions;
use super::{EagerVecBuilderOptions, Source};
#[derive(Clone)]
pub struct ComputedValueVecsFromDateIndex {
@@ -19,39 +19,44 @@ pub struct ComputedValueVecsFromDateIndex {
const VERSION: Version = Version::ZERO;
impl ComputedValueVecsFromDateIndex {
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<DateIndex, Sats>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
options: EagerVecBuilderOptions,
compute_dollars: bool,
) -> color_eyre::Result<Self> {
Ok(Self {
sats: ComputedVecsFromDateIndex::forced_import(
path,
name,
compute_source,
source,
version + VERSION,
format,
computation,
options,
)?,
bitcoin: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_in_btc"),
true,
Source::Compute,
version + VERSION,
format,
computation,
options,
)?,
dollars: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_in_usd"),
true,
Source::Compute,
version + VERSION,
format,
computation,
options,
)
.unwrap()

View File

@@ -3,11 +3,11 @@ use std::path::Path;
use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
use brk_vec::{AnyCollectableVec, CollectableVec, Computation, EagerVec, Format, StoredVec};
use crate::vecs::{Indexes, fetched, indexes};
use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
use super::{ComputedVecsFromHeight, StorableVecGeneatorOptions};
use super::{ComputedVecsFromHeight, EagerVecBuilderOptions};
#[derive(Clone)]
pub struct ComputedValueVecsFromHeight {
@@ -19,39 +19,44 @@ pub struct ComputedValueVecsFromHeight {
const VERSION: Version = Version::ZERO;
impl ComputedValueVecsFromHeight {
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<Height, Sats>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
options: EagerVecBuilderOptions,
compute_dollars: bool,
) -> color_eyre::Result<Self> {
Ok(Self {
sats: ComputedVecsFromHeight::forced_import(
path,
name,
compute_source,
source,
version + VERSION,
format,
computation,
options,
)?,
bitcoin: ComputedVecsFromHeight::forced_import(
path,
&format!("{name}_in_btc"),
true,
Source::Compute,
version + VERSION,
format,
computation,
options,
)?,
dollars: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&format!("{name}_in_usd"),
true,
Source::Compute,
version + VERSION,
format,
computation,
options,
)
.unwrap()

View File

@@ -4,13 +4,13 @@ use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Computation,
ComputedVecFrom3, Format, LazyVecFrom1, StoredIndex, StoredVec,
AnyCollectableVec, CloneableAnyIterableVec, CollectableVec, Computation, ComputedVecFrom3,
Format, LazyVecFrom1, StoredIndex, StoredVec,
};
use crate::vecs::{Indexes, fetched, indexes};
use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
use super::{ComputedVecsFromTxindex, StorableVecGeneatorOptions};
use super::{ComputedVecsFromTxindex, EagerVecBuilderOptions};
#[derive(Clone)]
pub struct ComputedValueVecsFromTxindex {
@@ -41,14 +41,13 @@ impl ComputedValueVecsFromTxindex {
path: &Path,
name: &str,
indexes: &indexes::Vecs,
source: Option<BoxedAnyIterableVec<TxIndex, Sats>>,
source: Source<TxIndex, Sats>,
version: Version,
computation: Computation,
format: Format,
fetched: Option<&fetched::Vecs>,
options: StorableVecGeneatorOptions,
options: EagerVecBuilderOptions,
) -> color_eyre::Result<Self> {
let compute_source = source.is_none();
let compute_dollars = fetched.is_some();
let name_in_btc = format!("{name}_in_btc");
@@ -57,16 +56,19 @@ impl ComputedValueVecsFromTxindex {
let sats = ComputedVecsFromTxindex::forced_import(
path,
name,
compute_source,
source.clone(),
version + VERSION,
format,
computation,
options,
)?;
let source_vec = source.vec();
let bitcoin_txindex = LazyVecFrom1::init(
&name_in_btc,
version + VERSION,
source.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
|txindex: TxIndex, iter| {
iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| {
let sats = value.into_owned();
@@ -78,9 +80,10 @@ impl ComputedValueVecsFromTxindex {
let bitcoin = ComputedVecsFromTxindex::forced_import(
path,
&name_in_btc,
false,
Source::None,
version + VERSION,
format,
computation,
options,
)?;
@@ -124,9 +127,10 @@ impl ComputedValueVecsFromTxindex {
ComputedVecsFromTxindex::forced_import(
path,
&name_in_usd,
false,
Source::None,
version + VERSION,
format,
computation,
options,
)
.unwrap()

View File

@@ -5,7 +5,7 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
use crate::vecs::{Indexes, fetched, indexes};
use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
#[derive(Clone)]
pub struct ComputedHeightValueVecs {
@@ -20,13 +20,13 @@ impl ComputedHeightValueVecs {
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<Height, Sats>,
version: Version,
format: Format,
compute_dollars: bool,
) -> color_eyre::Result<Self> {
Ok(Self {
sats: compute_source.then(|| {
sats: source.is_compute().then(|| {
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
.unwrap()
}),

View File

@@ -5,8 +5,8 @@ use brk_core::{
InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2ABytes, P2MSOutputIndex,
P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, P2PKHAddressIndex,
P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, P2WPKHAddressIndex,
P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, StoredUsize, Timestamp,
TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex,
P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, SemesterIndex, StoredUsize,
Timestamp, TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
@@ -50,6 +50,7 @@ pub struct Vecs {
pub monthindex_to_first_dateindex: EagerVec<MonthIndex, DateIndex>,
pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>,
pub monthindex_to_quarterindex: EagerVec<MonthIndex, QuarterIndex>,
pub monthindex_to_semesterindex: EagerVec<MonthIndex, SemesterIndex>,
pub monthindex_to_yearindex: EagerVec<MonthIndex, YearIndex>,
pub opreturnindex_to_opreturnindex:
ComputedVecFrom1<OpReturnIndex, OpReturnIndex, OpReturnIndex, TxIndex>,
@@ -76,6 +77,9 @@ pub struct Vecs {
pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>,
pub quarterindex_to_monthindex_count: EagerVec<QuarterIndex, StoredUsize>,
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_input_count:
ComputedVecFrom2<TxIndex, StoredUsize, TxIndex, InputIndex, InputIndex, OutputIndex>,
@@ -413,6 +417,12 @@ impl Vecs {
version + VERSION + Version::ZERO,
format,
)?,
monthindex_to_semesterindex: EagerVec::forced_import(
path,
"semesterindex",
version + VERSION + Version::ZERO,
format,
)?,
monthindex_to_yearindex: EagerVec::forced_import(
path,
"yearindex",
@@ -425,6 +435,12 @@ impl Vecs {
version + VERSION + Version::ZERO,
format,
)?,
semesterindex_to_first_monthindex: EagerVec::forced_import(
path,
"first_monthindex",
version + VERSION + Version::ZERO,
format,
)?,
weekindex_to_first_dateindex: EagerVec::forced_import(
path,
"first_dateindex",
@@ -443,6 +459,12 @@ impl Vecs {
version + VERSION + Version::ZERO,
format,
)?,
semesterindex_to_semesterindex: EagerVec::forced_import(
path,
"semesterindex",
version + VERSION + Version::ZERO,
format,
)?,
weekindex_to_weekindex: EagerVec::forced_import(
path,
"weekindex",
@@ -521,6 +543,12 @@ impl Vecs {
version + VERSION + Version::ZERO,
format,
)?,
semesterindex_to_monthindex_count: EagerVec::forced_import(
path,
"monthindex_count",
version + VERSION + Version::ZERO,
format,
)?,
yearindex_to_monthindex_count: EagerVec::forced_import(
path,
"monthindex_count",
@@ -943,6 +971,45 @@ impl Vecs {
exit,
)?;
// ---
// SemesterIndex
// ---
let starting_semesterindex = self
.monthindex_to_semesterindex
.into_iter()
.get_inner(starting_monthindex)
.unwrap_or_default();
self.monthindex_to_semesterindex.compute_from_index(
starting_monthindex,
&self.monthindex_to_first_dateindex,
exit,
)?;
self.semesterindex_to_first_monthindex
.compute_inverse_more_to_less(
starting_monthindex,
&self.monthindex_to_semesterindex,
exit,
)?;
// let semester_count = self.semesterindex_to_first_monthindex.len();
self.semesterindex_to_semesterindex.compute_from_index(
starting_semesterindex,
&self.semesterindex_to_first_monthindex,
exit,
)?;
self.semesterindex_to_monthindex_count
.compute_count_from_indexes(
starting_semesterindex,
&self.semesterindex_to_first_monthindex,
&self.monthindex_to_monthindex,
exit,
)?;
// ---
// YearIndex
// ---
@@ -1051,6 +1118,7 @@ impl Vecs {
weekindex: starting_weekindex,
monthindex: starting_monthindex,
quarterindex: starting_quarterindex,
semesterindex: starting_semesterindex,
yearindex: starting_yearindex,
decadeindex: starting_decadeindex,
difficultyepoch: starting_difficultyepoch,
@@ -1088,6 +1156,7 @@ impl Vecs {
&self.monthindex_to_first_dateindex,
&self.monthindex_to_monthindex,
&self.monthindex_to_quarterindex,
&self.monthindex_to_semesterindex,
&self.monthindex_to_yearindex,
&self.opreturnindex_to_opreturnindex,
&self.outputindex_to_outputindex,
@@ -1103,6 +1172,9 @@ impl Vecs {
&self.quarterindex_to_first_monthindex,
&self.quarterindex_to_monthindex_count,
&self.quarterindex_to_quarterindex,
&self.semesterindex_to_first_monthindex,
&self.semesterindex_to_monthindex_count,
&self.semesterindex_to_semesterindex,
&self.txindex_to_height,
&self.txindex_to_txindex,
&self.txindex_to_input_count,
@@ -1126,6 +1198,7 @@ pub struct Indexes {
pub weekindex: WeekIndex,
pub monthindex: MonthIndex,
pub quarterindex: QuarterIndex,
pub semesterindex: SemesterIndex,
pub yearindex: YearIndex,
pub decadeindex: DecadeIndex,
pub difficultyepoch: DifficultyEpoch,
@@ -1145,6 +1218,7 @@ impl Indexes {
self.weekindex = WeekIndex::from(self.dateindex);
self.monthindex = MonthIndex::from(self.dateindex);
self.quarterindex = QuarterIndex::from(self.monthindex);
self.semesterindex = SemesterIndex::from(self.monthindex);
self.yearindex = YearIndex::from(self.monthindex);
self.decadeindex = DecadeIndex::from(self.dateindex);
self.difficultyepoch = DifficultyEpoch::from(self.height);

File diff suppressed because it is too large Load Diff

View File

@@ -5,9 +5,11 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
use crate::vecs::grouped::Source;
use super::{
Indexes,
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, EagerVecBuilderOptions},
indexes,
};
@@ -24,33 +26,36 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
) -> color_eyre::Result<Self> {
Ok(Self {
indexes_to_difficulty: ComputedVecsFromHeight::forced_import(
path,
"difficulty",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
path,
"difficultyepoch",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import(
path,
"halvingepoch",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
})
}

View File

@@ -11,7 +11,7 @@ use crate::{
states::AddressCohortState,
vecs::{
Indexes, fetched,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedVecsFromHeight, EagerVecBuilderOptions, Source},
indexes, market,
stateful::{
common,
@@ -66,10 +66,11 @@ impl Vecs {
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
path,
&suffix("address_count"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
inner: common::Vecs::forced_import(
path,

View File

@@ -6,7 +6,8 @@ use brk_core::{
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, Format, VecIterator,
AnyCollectableVec, AnyIterableVec, AnyVec, CloneableAnyIterableVec, Computation, EagerVec,
Format, VecIterator,
};
use crate::{
@@ -16,7 +17,7 @@ use crate::{
grouped::{
ComputedHeightValueVecs, ComputedRatioVecsFromDateIndex,
ComputedValueVecsFromDateIndex, ComputedVecsFromDateIndex, ComputedVecsFromHeight,
StorableVecGeneatorOptions,
EagerVecBuilderOptions, Source,
},
indexes, market,
},
@@ -132,7 +133,7 @@ impl Vecs {
pub fn forced_import(
path: &Path,
cohort_name: Option<&str>,
_computation: Computation,
computation: Computation,
format: Format,
version: Version,
fetched: Option<&fetched::Vecs>,
@@ -144,8 +145,57 @@ impl Vecs {
let suffix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{name}_{s}"));
Ok(Self {
let dateindex_to_supply_in_profit = compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("supply_in_profit"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
});
let dateindex_to_supply_even = compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("supply_even"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
});
let dateindex_to_supply_in_loss = compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("supply_in_loss"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
});
let dateindex_to_unrealized_profit = compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("unrealized_profit"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
});
let dateindex_to_unrealized_loss = compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("unrealized_loss"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
});
Ok(Self {
height_to_supply_in_profit: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -155,27 +205,20 @@ impl Vecs {
)
.unwrap()
}),
dateindex_to_supply_in_profit: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("supply_in_profit"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
}),
indexes_to_supply_in_profit: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import(
path,
&suffix("supply_in_profit"),
false,
dateindex_to_supply_in_profit.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)
.unwrap()
}),
dateindex_to_supply_in_profit,
height_to_supply_even: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -185,27 +228,20 @@ impl Vecs {
)
.unwrap()
}),
dateindex_to_supply_even: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("supply_even"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
}),
indexes_to_supply_even: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import(
path,
&suffix("supply_even"),
false,
dateindex_to_supply_even.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)
.unwrap()
}),
dateindex_to_supply_even,
height_to_supply_in_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -215,27 +251,20 @@ impl Vecs {
)
.unwrap()
}),
dateindex_to_supply_in_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("supply_in_loss"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
}),
indexes_to_supply_in_loss: compute_dollars.then(|| {
ComputedValueVecsFromDateIndex::forced_import(
path,
&suffix("supply_in_loss"),
false,
dateindex_to_supply_in_loss.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)
.unwrap()
}),
dateindex_to_supply_in_loss,
height_to_unrealized_profit: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -245,26 +274,19 @@ impl Vecs {
)
.unwrap()
}),
dateindex_to_unrealized_profit: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("unrealized_profit"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
}),
indexes_to_unrealized_profit: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("unrealized_profit"),
false,
dateindex_to_unrealized_profit.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
dateindex_to_unrealized_profit,
height_to_unrealized_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -292,26 +314,19 @@ impl Vecs {
)
.unwrap()
}),
dateindex_to_unrealized_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("unrealized_loss"),
version + VERSION + Version::ZERO,
format,
)
.unwrap()
}),
indexes_to_unrealized_loss: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("unrealized_loss"),
false,
dateindex_to_unrealized_loss.as_ref().map(|v | v.boxed_clone()).into(),
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
dateindex_to_unrealized_loss,
height_to_realized_cap: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -325,10 +340,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_cap"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -336,10 +352,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("min_price_paid"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -347,10 +364,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("max_price_paid"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -363,7 +381,7 @@ impl Vecs {
height_to_supply_value: ComputedHeightValueVecs::forced_import(
path,
&suffix("supply"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -371,10 +389,11 @@ impl Vecs {
indexes_to_supply: ComputedValueVecsFromDateIndex::forced_import(
path,
&suffix("supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)?,
height_to_utxo_count: EagerVec::forced_import(
@@ -386,19 +405,21 @@ impl Vecs {
indexes_to_utxo_count: ComputedVecsFromHeight::forced_import(
path,
&suffix("utxo_count"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_realized_price: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_price"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -406,9 +427,10 @@ impl Vecs {
ComputedRatioVecsFromDateIndex::forced_import(
path,
&suffix("realized_price"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
)
.unwrap()
}),
@@ -425,10 +447,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_profit"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_sum()
.add_cumulative(),
)
@@ -447,10 +470,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_loss"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_sum()
.add_cumulative(),
)
@@ -460,10 +484,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("negative_realized_loss"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_sum().add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)
.unwrap()
}),
@@ -480,10 +505,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("value_created"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -491,10 +517,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_value"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -511,10 +538,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("adjusted_value_created"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -531,10 +559,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("value_destroyed"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -551,10 +580,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("adjusted_value_destroyed"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -562,10 +592,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("realized_cap_30d_change"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -573,10 +604,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("net_realized_profit_and_loss"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_sum()
.add_cumulative(),
)
@@ -612,7 +644,7 @@ impl Vecs {
height_to_halved_supply_value: ComputedHeightValueVecs::forced_import(
path,
&suffix("halved_supply"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -620,10 +652,11 @@ impl Vecs {
indexes_to_halved_supply: ComputedValueVecsFromDateIndex::forced_import(
path,
&suffix("halved_supply"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)?,
height_to_negative_unrealized_loss: compute_dollars.then(|| {
@@ -639,10 +672,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("negative_unrealized_loss"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -659,10 +693,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("net_unrealized_profit_and_loss"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -682,10 +717,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("net_unrealized_profit_and_loss_relative_to_market_cap"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
},
@@ -694,10 +730,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_profit_relative_to_realized_cap"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -705,10 +742,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_loss_relative_to_realized_cap"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -717,10 +755,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("net_realized_profit_and_loss_relative_to_realized_cap"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
EagerVecBuilderOptions::default().add_sum(),
)
.unwrap()
},
@@ -729,7 +768,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import(
path,
&suffix("supply_even"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -740,7 +779,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import(
path,
&suffix("supply_in_loss"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -751,7 +790,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import(
path,
&suffix("supply_in_profit"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -789,10 +828,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("supply_even_relative_to_own_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -800,10 +840,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("supply_in_loss_relative_to_own_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -811,10 +852,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("supply_in_profit_relative_to_own_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -822,10 +864,11 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("supply_relative_to_circulating_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -868,10 +911,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("supply_even_relative_to_circulating_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -881,10 +925,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("supply_in_loss_relative_to_circulating_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -894,10 +939,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("supply_in_profit_relative_to_circulating_supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -916,27 +962,30 @@ impl Vecs {
indexes_to_coinblocks_destroyed: ComputedVecsFromHeight::forced_import(
path,
&suffix("coinblocks_destroyed"),
true,
Source::Compute,
version + VERSION + Version::TWO,
format,
StorableVecGeneatorOptions::default().add_sum().add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_coindays_destroyed: ComputedVecsFromHeight::forced_import(
path,
&suffix("coindays_destroyed"),
true,
Source::Compute,
version + VERSION + Version::TWO,
format,
StorableVecGeneatorOptions::default().add_sum().add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_net_realized_profit_and_loss_cumulative_30d_change: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("net_realized_profit_and_loss_cumulative_30d_change"),
true,
Source::Compute,
version + VERSION + Version::new(3),
format,
StorableVecGeneatorOptions::default().add_last()
computation,
EagerVecBuilderOptions::default().add_last()
)
.unwrap()
}),
@@ -944,10 +993,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap"),
true,
Source::Compute,
version + VERSION + Version::new(3),
format,
StorableVecGeneatorOptions::default().add_last()
computation,
EagerVecBuilderOptions::default().add_last()
)
.unwrap()
}),
@@ -955,10 +1005,11 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap"),
true,
Source::Compute,
version + VERSION + Version::new(3),
format,
StorableVecGeneatorOptions::default().add_last()
computation,
EagerVecBuilderOptions::default().add_last()
)
.unwrap()
}),

View File

@@ -18,7 +18,7 @@ use crate::{
BlockState, SupplyState, Transacted,
stores::Stores,
vecs::{
grouped::ComputedVecsFromHeight,
grouped::{ComputedVecsFromHeight, Source},
market,
stateful::{
addresstype_to_addresscount::AddressTypeToAddressCount,
@@ -31,7 +31,7 @@ use crate::{
use super::{
Indexes, fetched,
grouped::{ComputedValueVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedValueVecsFromHeight, EagerVecBuilderOptions},
indexes, transactions,
};
@@ -78,7 +78,7 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> {
@@ -106,10 +106,11 @@ impl Vecs {
indexes_to_unspendable_supply: ComputedValueVecsFromHeight::forced_import(
path,
"unspendable_supply",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)?,
height_to_opreturn_supply: EagerVec::forced_import(
@@ -121,27 +122,30 @@ impl Vecs {
indexes_to_opreturn_supply: ComputedValueVecsFromHeight::forced_import(
path,
"opreturn_supply",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
compute_dollars,
)?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
path,
"address_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import(
path,
"empty_address_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
@@ -252,66 +256,74 @@ impl Vecs {
p2pk65: ComputedVecsFromHeight::forced_import(
path,
"p2pk65_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
path,
"p2pk33_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
path,
"p2pkh_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2sh: ComputedVecsFromHeight::forced_import(
path,
"p2sh_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
path,
"p2wpkh_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
path,
"p2wsh_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2tr: ComputedVecsFromHeight::forced_import(
path,
"p2tr_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2a: ComputedVecsFromHeight::forced_import(
path,
"p2a_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
},
),
@@ -320,73 +332,81 @@ impl Vecs {
p2pk65: ComputedVecsFromHeight::forced_import(
path,
"p2pk65_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
path,
"p2pk33_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
path,
"p2pkh_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2sh: ComputedVecsFromHeight::forced_import(
path,
"p2sh_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
path,
"p2wpkh_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
path,
"p2wsh_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2tr: ComputedVecsFromHeight::forced_import(
path,
"p2tr_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
p2a: ComputedVecsFromHeight::forced_import(
path,
"p2a_empty_address_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
},
),
utxo_vecs: utxo_cohorts::Vecs::forced_import(
path,
version,
_computation,
computation,
format,
fetched,
&states_path,
@@ -394,7 +414,7 @@ impl Vecs {
address_vecs: address_cohorts::Vecs::forced_import(
path,
version,
_computation,
computation,
format,
fetched,
&states_path,
@@ -1302,34 +1322,37 @@ impl Vecs {
// Capped as external drives (even thunderbolt 4 SSDs) can be overwhelmed
let chunk_size = (vecs.len() as f64 / 3.0).ceil() as usize;
vecs.into_par_iter().chunks(chunk_size).try_for_each(|v| {
v.into_iter().try_for_each(|either| match either {
Either::Left(v) => v.compute_rest_part2(
indexer,
indexes,
fetched,
starting_indexes,
market,
&height_to_supply,
dateindex_to_supply_ref,
height_to_realized_cap_ref,
dateindex_to_realized_cap_ref,
exit,
),
Either::Right(v) => v.compute_rest_part2(
indexer,
indexes,
fetched,
starting_indexes,
market,
&height_to_supply,
dateindex_to_supply_ref,
height_to_realized_cap_ref,
dateindex_to_realized_cap_ref,
exit,
),
})
})?;
vecs.into_par_iter()
// .into_iter()
.chunks(chunk_size)
.try_for_each(|v| {
v.into_iter().try_for_each(|either| match either {
Either::Left(v) => v.compute_rest_part2(
indexer,
indexes,
fetched,
starting_indexes,
market,
&height_to_supply,
dateindex_to_supply_ref,
height_to_realized_cap_ref,
dateindex_to_realized_cap_ref,
exit,
),
Either::Right(v) => v.compute_rest_part2(
indexer,
indexes,
fetched,
starting_indexes,
market,
&height_to_supply,
dateindex_to_supply_ref,
height_to_realized_cap_ref,
dateindex_to_realized_cap_ref,
exit,
),
})
})?;
self.indexes_to_unspendable_supply.compute_rest(
indexer,

View File

@@ -11,11 +11,13 @@ use brk_vec::{
ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, Format, StoredIndex, VecIterator,
};
use crate::vecs::grouped::Source;
use super::{
Indexes, fetched,
grouped::{
ComputedValueVecsFromHeight, ComputedValueVecsFromTxindex, ComputedVecsFromHeight,
ComputedVecsFromTxindex, StorableVecGeneatorOptions,
ComputedVecsFromTxindex, EagerVecBuilderOptions,
},
indexes,
};
@@ -237,7 +239,8 @@ impl Vecs {
// true,
// version + VERSION + Version::ZERO,
// format,
// StorableVecGeneatorOptions::default()
// computation,
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
// .add_cumulative(),
@@ -286,7 +289,8 @@ impl Vecs {
// true,
// version + VERSION + Version::ZERO,
// format,
// StorableVecGeneatorOptions::default()
// computation,
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
// .add_cumulative(),
@@ -339,10 +343,11 @@ impl Vecs {
indexes_to_tx_count: ComputedVecsFromHeight::forced_import(
path,
"tx_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -352,10 +357,11 @@ impl Vecs {
indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
path,
"input_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -365,10 +371,11 @@ impl Vecs {
indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
path,
"output_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -378,43 +385,40 @@ impl Vecs {
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
path,
"tx_v1",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_tx_v2: ComputedVecsFromHeight::forced_import(
path,
"tx_v2",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_tx_v3: ComputedVecsFromHeight::forced_import(
path,
"tx_v3",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_fee: ComputedValueVecsFromTxindex::forced_import(
path,
"fee",
indexes,
Some(txindex_to_fee.boxed_clone()),
Source::Vec(txindex_to_fee.boxed_clone()),
version + VERSION + Version::ZERO,
computation,
format,
fetched,
StorableVecGeneatorOptions::default()
EagerVecBuilderOptions::default()
.add_sum()
.add_cumulative()
.add_percentiles()
@@ -424,10 +428,11 @@ impl Vecs {
indexes_to_feerate: ComputedVecsFromTxindex::forced_import(
path,
"feerate",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -435,10 +440,11 @@ impl Vecs {
indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import(
path,
"tx_vsize",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -446,10 +452,11 @@ impl Vecs {
indexes_to_tx_weight: ComputedVecsFromTxindex::forced_import(
path,
"tx_weight",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -457,10 +464,11 @@ impl Vecs {
indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import(
path,
"subsidy",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_percentiles()
.add_sum()
.add_cumulative()
@@ -471,10 +479,11 @@ impl Vecs {
indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import(
path,
"coinbase",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_sum()
.add_cumulative()
.add_percentiles()
@@ -485,21 +494,21 @@ impl Vecs {
indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight::forced_import(
path,
"unclaimed_rewards",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
computation,
EagerVecBuilderOptions::default().add_sum().add_cumulative(),
compute_dollars,
)?,
indexes_to_p2a_count: ComputedVecsFromHeight::forced_import(
path,
"p2a_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -509,10 +518,11 @@ impl Vecs {
indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import(
path,
"p2ms_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -522,10 +532,11 @@ impl Vecs {
indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import(
path,
"p2pk33_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -535,10 +546,11 @@ impl Vecs {
indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import(
path,
"p2pk65_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -548,10 +560,11 @@ impl Vecs {
indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import(
path,
"p2pkh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -561,10 +574,11 @@ impl Vecs {
indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import(
path,
"p2sh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -574,10 +588,11 @@ impl Vecs {
indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import(
path,
"p2tr_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -587,10 +602,11 @@ impl Vecs {
indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import(
path,
"p2wpkh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -600,10 +616,11 @@ impl Vecs {
indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import(
path,
"p2wsh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -613,10 +630,11 @@ impl Vecs {
indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import(
path,
"opreturn_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -626,10 +644,11 @@ impl Vecs {
indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import(
path,
"unknownoutput_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -639,10 +658,11 @@ impl Vecs {
indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import(
path,
"emptyoutput_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
EagerVecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -652,10 +672,11 @@ impl Vecs {
indexes_to_exact_utxo_count: ComputedVecsFromHeight::forced_import(
path,
"exact_utxo_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
EagerVecBuilderOptions::default().add_last(),
)?,
txindex_to_is_coinbase,
inputindex_to_value,

View File

@@ -1,6 +1,6 @@
use std::{
cmp::Ordering,
ops::{Add, Div, Mul},
ops::{Add, AddAssign, Div, Mul},
};
use serde::Serialize;
@@ -20,6 +20,12 @@ impl Add for Bitcoin {
}
}
impl AddAssign for Bitcoin {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl Mul for Bitcoin {
type Output = Self;
fn mul(self, rhs: Self) -> Self::Output {

View File

@@ -31,6 +31,10 @@ impl Date {
pub fn day(&self) -> u8 {
(self.0 % 1_00) as u8
}
pub fn into_jiff(self) -> Date_ {
self.into()
}
}
impl Default for Date {

View File

@@ -3,11 +3,14 @@ use std::{
ops::{Add, Rem},
};
use jiff::Span;
use serde::Serialize;
// use color_eyre::eyre::eyre;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Error, Printable};
use crate::{
CheckedSub, DecadeIndex, Error, FromCoarserIndex, MonthIndex, Printable, QuarterIndex,
SemesterIndex, WeekIndex, YearIndex,
};
use super::Date;
@@ -103,3 +106,135 @@ impl Printable for DateIndex {
&["d", "date", "dateindex"]
}
}
impl FromCoarserIndex<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()
}
}

View File

@@ -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 {
fn from(value: usize) -> Self {
Self(value as u8)

View File

@@ -1,6 +1,6 @@
use std::{
fmt::Debug,
ops::{Add, Div},
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
@@ -54,6 +54,12 @@ impl Add for DifficultyEpoch {
}
}
impl AddAssign for DifficultyEpoch {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl Add<usize> for DifficultyEpoch {
type Output = Self;

View File

@@ -1,6 +1,6 @@
use std::{
cmp::Ordering,
ops::{Add, Div},
ops::{Add, AddAssign, Div},
};
use serde::Serialize;
@@ -35,6 +35,12 @@ impl Add for Feerate {
}
}
impl AddAssign for Feerate {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl Div<usize> for Feerate {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {

View File

@@ -1,6 +1,6 @@
use std::{
fmt::Debug,
ops::{Add, Div},
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
@@ -60,6 +60,12 @@ impl Add for HalvingEpoch {
}
}
impl AddAssign for HalvingEpoch {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl Add<usize> for HalvingEpoch {
type Output = Self;

View File

@@ -33,6 +33,7 @@ mod p2wshaddressindex;
mod quarterindex;
mod rawlocktime;
mod sats;
mod semesterindex;
mod stored_f32;
mod stored_f64;
mod stored_u32;
@@ -90,6 +91,7 @@ pub use p2wshaddressindex::*;
pub use quarterindex::*;
pub use rawlocktime::*;
pub use sats::*;
pub use semesterindex::*;
pub use stored_f32::*;
pub use stored_f64::*;
pub use stored_u8::*;

View File

@@ -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 {
fn from(value: usize) -> Self {
Self(value as u16)

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::{Deref, DerefMut};
use serde::{Serialize, Serializer, ser::SerializeTuple};
@@ -236,6 +236,15 @@ where
}
}
impl<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>
where
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>
where
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>
where
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>
where
T: Div<usize, Output = T>,

View File

@@ -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 {
fn from(value: QuarterIndex) -> Self {
value.0 as usize

View File

@@ -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"]
}
}

View File

@@ -1,7 +1,7 @@
use core::panic;
use std::{
cmp::Ordering,
ops::{Add, Div, Mul, Sub},
ops::{Add, AddAssign, Div, Mul, Sub},
};
use derive_deref::Deref;
@@ -70,6 +70,12 @@ impl Add for StoredF32 {
}
}
impl AddAssign for StoredF32 {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<StoredF32> for f32 {
fn from(value: StoredF32) -> Self {
value.0

View File

@@ -1,7 +1,7 @@
use std::{
cmp::Ordering,
f64,
ops::{Add, Div, Mul},
ops::{Add, AddAssign, Div, Mul},
};
use derive_deref::Deref;
@@ -65,6 +65,12 @@ impl Add for StoredF64 {
}
}
impl AddAssign for StoredF64 {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<StoredF64> for f64 {
fn from(value: StoredF64) -> Self {
value.0

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref;
use serde::Serialize;
@@ -73,6 +73,12 @@ impl Add for StoredU32 {
}
}
impl AddAssign for StoredU32 {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<f64> for StoredU32 {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref;
use serde::Serialize;
@@ -65,6 +65,12 @@ impl Add for StoredU64 {
}
}
impl AddAssign for StoredU64 {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<f64> for StoredU64 {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref;
use serde::Serialize;
@@ -66,6 +66,12 @@ impl Add for StoredU8 {
}
}
impl AddAssign for StoredU8 {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<f64> for StoredU8 {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
@@ -71,6 +71,12 @@ impl Add for StoredUsize {
}
}
impl AddAssign for StoredUsize {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<f64> for StoredUsize {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {

View File

@@ -1,6 +1,6 @@
use std::{
cmp::Ordering,
ops::{Add, Div},
ops::{Add, AddAssign, Div},
};
use derive_deref::Deref;
@@ -142,6 +142,12 @@ impl Add for Timestamp {
}
}
impl AddAssign for Timestamp {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl From<f64> for Timestamp {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {

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 {
fn from(value: u64) -> Self {
Self(value)

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 {
fn from(value: usize) -> Self {
Self(value as u16)
@@ -68,7 +74,6 @@ impl From<Date> for WeekIndex {
let d = jiff::civil::Date::new(year, 6, 6).unwrap();
let i = d.iso_week_date();
let w = i.weeks_in_year();
// dbg!(d, w);
week += w as u16;
year += 1;
}

View File

@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref;
use serde::Serialize;
@@ -58,6 +58,12 @@ impl Add for Weight {
}
}
impl AddAssign for Weight {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl Div<usize> for Weight {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {

View File

@@ -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)
}
}

View File

@@ -1,3 +1,5 @@
mod from_coarser;
mod printable;
pub use from_coarser::*;
pub use printable::*;

View File

@@ -7,7 +7,7 @@ pub fn setrlimit() -> io::Result<()> {
rlimit::setrlimit(
Resource::NOFILE,
no_file_limit.0.max(210_000),
no_file_limit.0.max(250_000),
no_file_limit.1,
)?;

View File

@@ -4,7 +4,8 @@ use brk_core::{
DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex,
MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex,
P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex,
P2WSHAddressIndex, Printable, QuarterIndex, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex,
P2WSHAddressIndex, Printable, QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex,
WeekIndex, YearIndex,
};
use color_eyre::eyre::eyre;
use schemars::JsonSchema;
@@ -52,6 +53,8 @@ pub enum Index {
P2WSHAddressIndex,
#[schemars(description = "Quarter index")]
QuarterIndex,
#[schemars(description = "Semester index")]
SemesterIndex,
#[schemars(description = "Transaction index")]
TxIndex,
#[schemars(description = "Unknown output index")]
@@ -63,7 +66,7 @@ pub enum Index {
}
impl Index {
pub fn all() -> [Self; 24] {
pub fn all() -> [Self; 25] {
[
Self::DateIndex,
Self::DecadeIndex,
@@ -85,6 +88,7 @@ impl Index {
Self::P2WPKHAddressIndex,
Self::P2WSHAddressIndex,
Self::QuarterIndex,
Self::SemesterIndex,
Self::TxIndex,
Self::UnknownOutputIndex,
Self::WeekIndex,
@@ -114,6 +118,7 @@ impl Index {
Self::P2WPKHAddressIndex => P2WPKHAddressIndex::to_possible_strings(),
Self::P2WSHAddressIndex => P2WSHAddressIndex::to_possible_strings(),
Self::QuarterIndex => QuarterIndex::to_possible_strings(),
Self::SemesterIndex => SemesterIndex::to_possible_strings(),
Self::TxIndex => TxIndex::to_possible_strings(),
Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(),
Self::WeekIndex => WeekIndex::to_possible_strings(),
@@ -174,7 +179,7 @@ impl TryFrom<&str> for Index {
Self::P2WSHAddressIndex
}
v if (Self::QuarterIndex).possible_values().contains(&v) => Self::QuarterIndex,
v if (Self::QuarterIndex).possible_values().contains(&v) => Self::QuarterIndex,
v if (Self::SemesterIndex).possible_values().contains(&v) => Self::SemesterIndex,
v if (Self::TxIndex).possible_values().contains(&v) => Self::TxIndex,
v if (Self::WeekIndex).possible_values().contains(&v) => Self::WeekIndex,
v if (Self::YearIndex).possible_values().contains(&v) => Self::YearIndex,

View File

@@ -6,9 +6,9 @@
use std::collections::BTreeMap;
use brk_computer::Computer;
use brk_core::Result;
use brk_core::{Height, Result};
use brk_indexer::Indexer;
use brk_vec::AnyCollectableVec;
use brk_vec::{AnyCollectableVec, AnyIndexedVec};
use tabled::settings::Style;
mod deser;
@@ -46,6 +46,10 @@ impl<'a> Interface<'a> {
}
}
pub fn get_height(&self) -> Height {
self._indexer.vecs.height_to_blockhash.height()
}
pub fn search(&self, params: &Params) -> Vec<(String, &&dyn AnyCollectableVec)> {
let tuples = params
.ids

View File

@@ -31,7 +31,7 @@ serde = { workspace = true }
tokio = { workspace = true }
tower-http = { version = "0.6.6", features = ["compression-full", "trace"] }
tracing = "0.1.41"
zip = "4.2.0"
zip = "4.3.0"
[package.metadata.cargo-machete]
ignored = ["clap"]

View File

@@ -48,6 +48,8 @@ fn req_to_response_res(
let to = params.to();
let format = params.format();
// TODO: From and to should be capped here
let weight = vecs
.iter()
.map(|(_, v)| v.range_weight(from, to))
@@ -57,7 +59,8 @@ fn req_to_response_res(
return Err(eyre!("Request is too heavy, max weight is {MAX_WEIGHT}"));
}
let etag = vecs.first().unwrap().1.etag(to);
// TODO: height should be from vec, but good enough for now
let etag = vecs.first().unwrap().1.etag(interface.get_height(), to);
if headers
.get_if_none_match()

View File

@@ -1,4 +1,4 @@
use brk_core::Version;
use brk_core::{Height, Version};
use super::{BoxedVecIterator, StoredIndex, StoredType};
@@ -20,10 +20,10 @@ pub trait AnyVec: Send + Sync {
}
fn index_type_to_string(&self) -> &'static str;
fn value_type_to_size_of(&self) -> usize;
fn etag(&self, to: Option<i64>) -> String {
fn etag(&self, height: Height, to: Option<i64>) -> String {
let len = self.len();
format!(
"{}-{:?}",
"{}-{}-{}",
to.map_or(len, |to| {
if to.is_negative() {
len.checked_sub(to.unsigned_abs() as usize)
@@ -32,7 +32,8 @@ pub trait AnyVec: Send + Sync {
to as usize
}
}),
self.version()
u64::from(self.version()),
u32::from(height),
)
}

View File

@@ -122,13 +122,14 @@ where
fn file_write_all(&mut self, file: &mut File, buf: &[u8]) -> Result<()> {
file.write_all(buf)?;
// file.flush()?;
// file.sync_data()?;
self.update_mmap(file)
}
fn file_truncate_and_write_all(&mut self, file: &mut File, len: u64, buf: &[u8]) -> Result<()> {
Self::file_set_len_(file, len)?;
file.write_all(buf)?;
self.update_mmap(file)
self.file_write_all(file, buf)
}
fn reset(&mut self) -> Result<()>;

View File

@@ -92,7 +92,7 @@ where
S3T: StoredType,
{
pub fn forced_import_or_init_from_1(
mode: Computation,
computation: Computation,
path: &Path,
name: &str,
version: Version,
@@ -100,7 +100,7 @@ where
source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Result<Self> {
Ok(match mode {
Ok(match computation {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, name, version, format)?,
deps: Dependencies::From1(source, compute),
@@ -114,7 +114,7 @@ where
#[allow(clippy::too_many_arguments)]
pub fn forced_import_or_init_from_2(
mode: Computation,
computation: Computation,
path: &Path,
name: &str,
version: Version,
@@ -123,7 +123,7 @@ where
source2: BoxedAnyIterableVec<S2I, S2T>,
compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>,
) -> Result<Self> {
Ok(match mode {
Ok(match computation {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, name, version, format)?,
deps: Dependencies::From2((source1, source2), compute),
@@ -137,7 +137,7 @@ where
#[allow(clippy::too_many_arguments)]
pub fn forced_import_or_init_from_3(
mode: Computation,
computation: Computation,
path: &Path,
name: &str,
version: Version,
@@ -147,7 +147,7 @@ where
source3: BoxedAnyIterableVec<S3I, S3T>,
compute: ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
) -> Result<Self> {
Ok(match mode {
Ok(match computation {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, name, version, format)?,
deps: Dependencies::From3((source1, source2, source3), compute),

View File

@@ -35,10 +35,6 @@ where
source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Self {
if source.index_type_to_string() != I::to_string() {
panic!("Should have same index");
}
Self {
name: name.to_string(),
version,

View File

@@ -184,11 +184,13 @@ function createChartElement({
? 1
: index === /** @satisfies {QuarterIndex} */ (19)
? 2
: index === /** @satisfies {YearIndex} */ (23)
? 6
: index === /** @satisfies {DecadeIndex} */ (1)
? 60
: 0.5;
: index === /** @satisfies {SemesterIndex} */ (20)
? 3
: index === /** @satisfies {YearIndex} */ (24)
? 6
: index === /** @satisfies {DecadeIndex} */ (1)
? 60
: 0.5;
ichart.applyOptions({
timeScale: {
@@ -474,7 +476,8 @@ function createChartElement({
timeScaleSetCallback?.(() => {
if (
index === /** @satisfies {QuarterIndex} */ (19) ||
index === /** @satisfies {YearIndex} */ (23) ||
index === /** @satisfies {SemesterIndex} */ (20) ||
index === /** @satisfies {YearIndex} */ (24) ||
index === /** @satisfies {DecadeIndex} */ (1)
) {
ichart.timeScale().setVisibleLogicalRange({

View File

@@ -7,7 +7,7 @@ const LINE = "line";
const CANDLE = "candle";
/**
* @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "year" | "decade" } SerializedChartableIndex
* @typedef {"timestamp" | "date" | "week" | "d.epoch" | "month" | "quarter" | "semester" | "year" | "decade" } SerializedChartableIndex
*/
/**
@@ -205,14 +205,17 @@ export function init({
break;
}
default: {
if (index === /** @satisfies {WeekIndex} */ (22)) {
if (index === /** @satisfies {WeekIndex} */ (23)) {
date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7));
} else if (index === /** @satisfies {MonthIndex} */ (7)) {
date.setUTCDate(1);
} else if (index === /** @satisfies {QuarterIndex} */ (19)) {
const month = date.getUTCMonth();
date.setUTCMonth(month - (month % 3), 1);
} else if (index === /** @satisfies {YearIndex} */ (23)) {
} else if (index === /** @satisfies {SemesterIndex} */ (20)) {
const month = date.getUTCMonth();
date.setUTCMonth(month - (month % 6), 1);
} else if (index === /** @satisfies {YearIndex} */ (24)) {
date.setUTCMonth(0, 1);
} else if (index === /** @satisfies {DecadeIndex} */ (1)) {
date.setUTCFullYear(
@@ -465,6 +468,7 @@ function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
"d.epoch",
"month",
"quarter",
"semester",
"year",
// "halving epoch",
"decade",

View File

@@ -6,7 +6,7 @@
* @import * as _ from "../packages/ufuzzy/v1.0.18/types"
* @import { SerializedChartableIndex } from "./chart";
* @import { Signal, Signals, Accessor } from "../packages/solid-signals/wrapper";
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes"
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, SemesterIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes"
*/
/**
@@ -1164,13 +1164,15 @@ function createUtils() {
return "p2wshaddressindex";
case /** @satisfies {QuarterIndex} */ (19):
return "quarterindex";
case /** @satisfies {TxIndex} */ (20):
case /** @satisfies {SemesterIndex} */ (20):
return "semesterindex";
case /** @satisfies {TxIndex} */ (21):
return "txindex";
case /** @satisfies {UnknownOutputIndex} */ (21):
case /** @satisfies {UnknownOutputIndex} */ (22):
return "unknownoutputindex";
case /** @satisfies {WeekIndex} */ (22):
case /** @satisfies {WeekIndex} */ (23):
return "weekindex";
case /** @satisfies {YearIndex} */ (23):
case /** @satisfies {YearIndex} */ (24):
return "yearindex";
}
},
@@ -1196,9 +1198,11 @@ function createUtils() {
return "month";
case /** @satisfies {QuarterIndex} */ (19):
return "quarter";
case /** @satisfies {WeekIndex} */ (22):
case /** @satisfies {SemesterIndex} */ (20):
return "semester";
case /** @satisfies {WeekIndex} */ (23):
return "week";
case /** @satisfies {YearIndex} */ (23):
case /** @satisfies {YearIndex} */ (24):
return "year";
default:
return null;
@@ -1215,15 +1219,17 @@ function createUtils() {
case "date":
return /** @satisfies {DateIndex} */ (0);
case "week":
return /** @satisfies {WeekIndex} */ (22);
return /** @satisfies {WeekIndex} */ (23);
case "d.epoch":
return /** @satisfies {DifficultyEpoch} */ (2);
case "month":
return /** @satisfies {MonthIndex} */ (7);
case "quarter":
return /** @satisfies {QuarterIndex} */ (19);
case "semester":
return /** @satisfies {SemesterIndex} */ (20);
case "year":
return /** @satisfies {YearIndex} */ (23);
return /** @satisfies {YearIndex} */ (24);
case "decade":
return /** @satisfies {DecadeIndex} */ (1);
default:

View File

@@ -406,6 +406,7 @@ function createSerializedIndexes() {
/** @satisfies {VecId} */ ("inputindex"),
/** @satisfies {VecId} */ ("monthindex"),
/** @satisfies {VecId} */ ("opreturnindex"),
/** @satisfies {VecId} */ ("semesterindex"),
/** @satisfies {VecId} */ ("outputindex"),
/** @satisfies {VecId} */ ("p2aaddressindex"),
/** @satisfies {VecId} */ ("p2msoutputindex"),
@@ -437,21 +438,23 @@ function serializedIndexToIndex(serializedIndex) {
case "dateindex":
return /** @satisfies {DateIndex} */ (0);
case "weekindex":
return /** @satisfies {WeekIndex} */ (22);
return /** @satisfies {WeekIndex} */ (23);
case "difficultyepoch":
return /** @satisfies {DifficultyEpoch} */ (2);
case "monthindex":
return /** @satisfies {MonthIndex} */ (7);
case "quarterindex":
return /** @satisfies {QuarterIndex} */ (19);
case "semesterindex":
return /** @satisfies {SemesterIndex} */ (20);
case "yearindex":
return /** @satisfies {YearIndex} */ (23);
return /** @satisfies {YearIndex} */ (24);
case "decadeindex":
return /** @satisfies {DecadeIndex} */ (1);
case "halvingepoch":
return /** @satisfies {HalvingEpoch} */ (4);
case "txindex":
return /** @satisfies {TxIndex} */ (20);
return /** @satisfies {TxIndex} */ (21);
case "inputindex":
return /** @satisfies {InputIndex} */ (6);
case "outputindex":
@@ -479,7 +482,7 @@ function serializedIndexToIndex(serializedIndex) {
case "emptyoutputindex":
return /** @satisfies {EmptyOutputIndex} */ (3);
case "unknownoutputindex":
return /** @satisfies {UnknownOutputIndex} */ (21);
return /** @satisfies {UnknownOutputIndex} */ (22);
}
}