Compare commits

...

14 Commits

Author SHA1 Message Date
nym21 a98546f605 release: v0.0.78 2025-07-13 02:05:28 +02:00
nym21 3567559d4e release: v0.0.77 2025-07-13 01:54:51 +02:00
nym21 216476ee45 computer: reduce number of ratio datasets for some cohorts 2025-07-13 01:25:45 +02:00
nym21 3fc28c07fb computer: missed a file 2025-07-13 00:23:32 +02:00
nym21 85f6ef063d computer: perf again 2025-07-13 00:21:20 +02:00
nym21 1e71e2d68f computer: perf 2025-07-12 16:17:29 +02:00
nym21 b24a29895f global: perf + resource imprv 2025-07-12 15:07:02 +02:00
nym21 0167a2ae59 global: fixes 2025-07-12 11:18:51 +02:00
nym21 2c867103ca computer: remove dbg 2025-07-11 14:23:26 +02:00
nym21 8c289df336 computer: stateful: perf improvements 2025-07-11 11:43:53 +02:00
nym21 4489920cbf computer: fix coarse lazy indexes 2025-07-11 01:51:04 +02:00
nym21 029a85081b global: snapshot 2025-07-10 22:32:04 +02:00
nym21 1bc739d07f vec + comp: small changes 2025-07-10 18:35:54 +02:00
nym21 c229e218f6 global: adding semester + making coarser intervals computed instead of eager 2025-07-10 17:44:19 +02:00
94 changed files with 5022 additions and 2325 deletions
+5
View File
@@ -18,3 +18,8 @@ _*
# Logs
.log
# Profiling
profile.json.gz
flamegraph.svg
*.trace
Generated
+41 -40
View File
@@ -477,7 +477,7 @@ dependencies = [
[[package]]
name = "brk"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"brk_bundler",
"brk_cli",
@@ -497,7 +497,7 @@ dependencies = [
[[package]]
name = "brk_bundler"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"brk_rolldown",
"log",
@@ -508,7 +508,7 @@ dependencies = [
[[package]]
name = "brk_cli"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"bitcoincore-rpc",
"brk_computer",
@@ -531,7 +531,7 @@ dependencies = [
[[package]]
name = "brk_computer"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"bincode",
"bitcoin",
@@ -558,7 +558,7 @@ dependencies = [
[[package]]
name = "brk_core"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"bincode",
"bitcoin",
@@ -579,7 +579,7 @@ dependencies = [
[[package]]
name = "brk_exit"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"brk_logger",
"ctrlc",
@@ -588,7 +588,7 @@ dependencies = [
[[package]]
name = "brk_fetcher"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"brk_core",
"brk_logger",
@@ -600,7 +600,7 @@ dependencies = [
[[package]]
name = "brk_indexer"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
@@ -618,7 +618,7 @@ dependencies = [
[[package]]
name = "brk_interface"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"brk_computer",
"brk_core",
@@ -636,7 +636,7 @@ dependencies = [
[[package]]
name = "brk_logger"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"color-eyre",
"env_logger",
@@ -646,7 +646,7 @@ dependencies = [
[[package]]
name = "brk_mcp"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"axum",
"brk_interface",
@@ -656,7 +656,7 @@ dependencies = [
[[package]]
name = "brk_parser"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
@@ -1025,7 +1025,7 @@ dependencies = [
[[package]]
name = "brk_server"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"axum",
"bitcoincore-rpc",
@@ -1055,7 +1055,7 @@ dependencies = [
[[package]]
name = "brk_store"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"brk_core",
"byteview",
@@ -1077,7 +1077,7 @@ dependencies = [
[[package]]
name = "brk_vec"
version = "0.0.76"
version = "0.0.78"
dependencies = [
"arc-swap",
"brk_core",
@@ -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"
@@ -4240,9 +4240,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.9.0"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f271e09bde39ab52250160a67e88577e0559ad77e9085de6e9051a2c4353f8f8"
checksum = "0207d6ed1852c2a124c1fbec61621acb8330d2bf969a5d0643131e9affd985a5"
dependencies = [
"indexmap 2.10.0",
"serde",
@@ -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",
+17 -17
View File
@@ -4,7 +4,7 @@ members = ["crates/*"]
package.description = "The Bitcoin Research Kit is a suite of tools designed to extract, compute and display data stored on a Bitcoin Core node"
package.license = "MIT"
package.edition = "2024"
package.version = "0.0.76"
package.version = "0.0.78"
package.homepage = "https://bitcoinresearchkit.org"
package.repository = "https://github.com/bitcoinresearchkit/brk"
@@ -26,25 +26,25 @@ axum = "0.8.4"
bincode = { version = "2.0.1", features = ["serde"] }
bitcoin = { version = "0.32.6", features = ["serde"] }
bitcoincore-rpc = "0.19.0"
brk_bundler = { version = "0.0.76", path = "crates/brk_bundler" }
brk_cli = { version = "0.0.76", path = "crates/brk_cli" }
brk_computer = { version = "0.0.76", path = "crates/brk_computer" }
brk_core = { version = "0.0.76", path = "crates/brk_core" }
brk_exit = { version = "0.0.76", path = "crates/brk_exit" }
brk_fetcher = { version = "0.0.76", path = "crates/brk_fetcher" }
brk_indexer = { version = "0.0.76", path = "crates/brk_indexer" }
brk_interface = { version = "0.0.76", path = "crates/brk_interface" }
brk_logger = { version = "0.0.76", path = "crates/brk_logger" }
brk_mcp = { version = "0.0.76", path = "crates/brk_mcp" }
brk_parser = { version = "0.0.76", path = "crates/brk_parser" }
brk_bundler = { version = "0.0.78", path = "crates/brk_bundler" }
brk_cli = { version = "0.0.78", path = "crates/brk_cli" }
brk_computer = { version = "0.0.78", path = "crates/brk_computer" }
brk_core = { version = "0.0.78", path = "crates/brk_core" }
brk_exit = { version = "0.0.78", path = "crates/brk_exit" }
brk_fetcher = { version = "0.0.78", path = "crates/brk_fetcher" }
brk_indexer = { version = "0.0.78", path = "crates/brk_indexer" }
brk_interface = { version = "0.0.78", path = "crates/brk_interface" }
brk_logger = { version = "0.0.78", path = "crates/brk_logger" }
brk_mcp = { version = "0.0.78", path = "crates/brk_mcp" }
brk_parser = { version = "0.0.78", path = "crates/brk_parser" }
brk_rmcp = { version = "0.2.1", features = ["transport-streamable-http-server", "transport-worker"]}
# brk_rmcp = { path = "../rust-sdk/crates/rmcp", features = ["transport-streamable-http-server", "transport-worker"]}
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" }
brk_server = { version = "0.0.78", path = "crates/brk_server" }
brk_store = { version = "0.0.78", path = "crates/brk_store" }
brk_vec = { version = "0.0.78", 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"
+8 -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
@@ -50,6 +55,7 @@
- api
- add extensions support (.json .csv …)
- if format instead of extension then don't download file
- add support for https (rustls)
- _vec_
- add native lock file support (once it's available in stable rust)
- improve compressed mode (slow reads)
@@ -73,6 +79,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
-2
View File
@@ -1,2 +0,0 @@
profile.json.gz
flamegraph.svg
+1 -1
View File
@@ -24,7 +24,7 @@ color-eyre = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
toml = "0.9.0"
toml = "0.9.1"
[[bin]]
name = "brk"
+4 -3
View File
@@ -13,7 +13,8 @@ pub fn main() -> color_eyre::Result<()> {
brk_logger::init(Some(Path::new(".log")));
let bitcoin_dir = default_bitcoin_path();
// let bitcoin_dir = default_bitcoin_path();
let bitcoin_dir = Path::new("/Volumes/WD_BLACK/bitcoin");
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
"http://localhost:8332",
@@ -23,11 +24,11 @@ pub fn main() -> color_eyre::Result<()> {
// Can't increase main thread's stack programatically, thus we need to use another thread
thread::Builder::new()
.stack_size(32 * 1024 * 1024)
.stack_size(256 * 1024 * 1024)
.spawn(move || -> color_eyre::Result<()> {
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
let _outputs_dir = default_brk_path().join("outputs");
let _outputs_dir = Path::new("/Volumes/WD_BLACK/brk").join("outputs");
let outputs_dir = _outputs_dir.as_path();
// let outputs_dir = Path::new("../../_outputs");
+2
View File
@@ -0,0 +1,2 @@
cargo build --profile profiling
flamegraph -- ../../target/profiling/examples/main
+2
View File
@@ -0,0 +1,2 @@
cargo build --example main --profile profiling
samply record ../../target/profiling/examples/main
+29 -22
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, VecBuilderOptions},
indexes,
};
@@ -34,8 +36,9 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
) -> color_eyre::Result<Self> {
Ok(Self {
height_to_interval: EagerVec::forced_import(
@@ -47,18 +50,22 @@ impl Vecs {
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
path,
"timestamp",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
computation,
indexes,
VecBuilderOptions::default().add_first(),
)?,
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
path,
"block_interval",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -66,32 +73,32 @@ 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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
height_to_vbytes: EagerVec::forced_import(
path,
@@ -102,12 +109,12 @@ 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,
indexes,
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
difficultyepoch_to_timestamp: EagerVec::forced_import(
path,
+96 -55
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, VecBuilderOptions},
indexes,
};
@@ -51,8 +51,9 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
@@ -61,194 +62,234 @@ 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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaultedness: ComputedVecsFromHeight::forced_import(
path,
"vaultedness",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)?,
indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import(
path,
"active_supply",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)?,
indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import(
path,
"thermo_cap",
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"vaulted_price",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
indexes,
true,
)?,
indexes_to_active_price: ComputedVecsFromHeight::forced_import(
path,
"active_price",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"active_price",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
indexes,
true,
)?,
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,
indexes,
VecBuilderOptions::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,
true,
)?,
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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
path,
"cointime_price",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
indexes,
true,
)?,
})
}
+21 -10
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, VecBuilderOptions},
indexes,
};
@@ -25,41 +27,50 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
) -> 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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_1: ComputedVecsFromHeight::forced_import(
path,
"constant_1",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_50: ComputedVecsFromHeight::forced_import(
path,
"constant_50",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_100: ComputedVecsFromHeight::forced_import(
path,
"constant_100",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)?,
})
}
+137 -37
View File
@@ -2,18 +2,21 @@ 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 brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, Format, StoredIndex,
};
use crate::vecs::grouped::Source;
use super::{
Indexes,
grouped::{
ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, StorableVecGeneatorOptions,
},
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, VecBuilderOptions},
indexes,
};
@@ -57,6 +60,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,8 +77,9 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
) -> color_eyre::Result<Self> {
let mut fetched_path = path.to_owned();
fetched_path.pop();
@@ -83,7 +89,7 @@ impl Vecs {
dateindex_to_ohlc_in_cents: EagerVec::forced_import(
&fetched_path,
"ohlc_in_cents",
version + VERSION + Version::ZERO,
version + Version::ZERO,
format,
)?,
dateindex_to_ohlc: EagerVec::forced_import(
@@ -125,7 +131,7 @@ impl Vecs {
height_to_ohlc_in_cents: EagerVec::forced_import(
&fetched_path,
"ohlc_in_cents",
version + VERSION + Version::ZERO,
version + Version::ZERO,
format,
)?,
height_to_ohlc: EagerVec::forced_import(
@@ -167,122 +173,138 @@ impl Vecs {
timeindexes_to_open: ComputedVecsFromDateIndex::forced_import(
path,
"open",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
computation,
indexes,
VecBuilderOptions::default().add_first(),
)?,
timeindexes_to_high: ComputedVecsFromDateIndex::forced_import(
path,
"high",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_max(),
computation,
indexes,
VecBuilderOptions::default().add_max(),
)?,
timeindexes_to_low: ComputedVecsFromDateIndex::forced_import(
path,
"low",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_min(),
computation,
indexes,
VecBuilderOptions::default().add_min(),
)?,
timeindexes_to_close: ComputedVecsFromDateIndex::forced_import(
path,
"close",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
path,
"open",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_first(),
VecBuilderOptions::default().add_first(),
)?,
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
path,
"high",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_max(),
VecBuilderOptions::default().add_max(),
)?,
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
path,
"low",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_min(),
VecBuilderOptions::default().add_min(),
)?,
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
path,
"close",
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
VecBuilderOptions::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(),
VecBuilderOptions::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(),
VecBuilderOptions::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(),
VecBuilderOptions::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(),
VecBuilderOptions::default().add_last(),
)?,
weekindex_to_ohlc: EagerVec::forced_import(
path,
@@ -332,6 +354,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",
@@ -426,12 +460,18 @@ impl Vecs {
starting_indexes.dateindex,
&indexes.dateindex_to_date,
|(di, d, this)| {
let mut ohlc = fetcher.get_date(d).unwrap_or_else(|_| {
let get_prev = || {
this.get_or_read(di, &this.mmap().load())
.unwrap()
.unwrap()
.into_owned()
});
};
let mut ohlc = if di.unwrap_to_usize() + 100 >= this.len() {
fetcher.get_date(d).unwrap_or_else(|_| get_prev())
} else {
get_prev()
};
if let Some(prev) = di.decremented() {
let prev_open = *this
@@ -610,12 +650,15 @@ impl Vecs {
starting_indexes.weekindex,
self.timeindexes_to_close.weekindex.unwrap_last(),
|(i, close, ..)| {
let open = weekindex_first_iter.unwrap_get_inner(i);
let high = weekindex_max_iter.unwrap_get_inner(i);
let low = weekindex_min_iter.unwrap_get_inner(i);
(
i,
OHLCDollars {
open: weekindex_first_iter.unwrap_get_inner(i),
high: weekindex_max_iter.unwrap_get_inner(i),
low: weekindex_min_iter.unwrap_get_inner(i),
open,
high,
low,
close,
},
)
@@ -693,6 +736,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 +1108,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 +1231,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 +1241,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,
@@ -0,0 +1,474 @@
use std::path::Path;
use brk_core::{FromCoarserIndex, Result, Version};
use brk_exit::Exit;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, Computation,
ComputedVec, ComputedVecFrom2, Format, StoredIndex,
};
use crate::vecs::grouped::{EagerVecBuilder, VecBuilderOptions};
use super::ComputedType;
#[allow(clippy::type_complexity)]
#[derive(Clone)]
pub struct ComputedVecBuilder<I, T, S1I, S2T>
where
I: StoredIndex,
T: ComputedType,
S2T: ComputedType,
{
pub first: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
pub average: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
pub sum: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
pub max: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
pub min: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
pub last: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
pub cumulative: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
}
const VERSION: Version = Version::ZERO;
impl<I, T, S1I, S2T> ComputedVecBuilder<I, T, S1I, S2T>
where
I: StoredIndex,
T: ComputedType + 'static,
S1I: StoredIndex + 'static + FromCoarserIndex<I>,
S2T: ComputedType,
{
#[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>,
len_source: BoxedAnyIterableVec<I, S2T>,
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_2(
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()),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
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_2(
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(),
),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
source
.next_at(S1I::max_from(i, source.len()))
.map(|(_, cow)| cow.into_owned())
},
)
.unwrap(),
)
}),
min: options.min.then(|| {
Box::new(
ComputedVec::forced_import_or_init_from_2(
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()),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
S1I::inclusive_range_from(i, source.len())
.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_2(
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()),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
S1I::inclusive_range_from(i, source.len())
.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_2(
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()),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
let vec = S1I::inclusive_range_from(i, source.len())
.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_2(
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()),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
let vec = S1I::inclusive_range_from(i, source.len())
.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_2(
computation,
path,
&suffix("cumulative"),
version + VERSION + Version::ZERO,
format,
source_extra.cumulative.as_ref().unwrap().boxed_clone(),
len_source.clone(),
|i: I, source, len_source| {
if i.unwrap_to_usize() >= len_source.len() {
return None;
}
source
.next_at(S1I::max_from(i, source.len()))
.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) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
self.first.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_average(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
self.average.as_ref().unwrap()
}
pub fn unwrap_sum(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
self.sum.as_ref().unwrap()
}
pub fn unwrap_max(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
self.max.as_ref().unwrap()
}
pub fn unwrap_min(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
self.min.as_ref().unwrap()
}
pub fn unwrap_last(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
self.last.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_cumulative(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
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<VecBuilderOptions> for ComputedVecBuilderOptions {
fn from(value: VecBuilderOptions) -> Self {
Self {
average: value.average(),
sum: value.sum(),
max: value.max(),
min: value.min(),
first: value.first(),
last: value.last(),
cumulative: value.cumulative(),
}
}
}
impl ComputedVecBuilderOptions {
pub fn add_first(mut self) -> Self {
self.first = true;
self
}
pub fn add_last(mut self) -> Self {
self.last = true;
self
}
pub fn add_min(mut self) -> Self {
self.min = true;
self
}
pub fn add_max(mut self) -> Self {
self.max = true;
self
}
pub fn add_average(mut self) -> Self {
self.average = true;
self
}
pub fn add_sum(mut self) -> Self {
self.sum = true;
self
}
pub fn add_cumulative(mut self) -> Self {
self.cumulative = true;
self
}
#[allow(unused)]
pub fn rm_min(mut self) -> Self {
self.min = false;
self
}
#[allow(unused)]
pub fn rm_max(mut self) -> Self {
self.max = false;
self
}
#[allow(unused)]
pub fn rm_average(mut self) -> Self {
self.average = false;
self
}
#[allow(unused)]
pub fn rm_sum(mut self) -> Self {
self.sum = false;
self
}
#[allow(unused)]
pub fn rm_cumulative(mut self) -> Self {
self.cumulative = false;
self
}
pub fn add_minmax(mut self) -> Self {
self.min = true;
self.max = true;
self
}
pub fn is_only_one_active(&self) -> bool {
[
self.average,
self.sum,
self.max,
self.min,
self.first,
self.last,
self.cumulative,
]
.iter()
.filter(|b| **b)
.count()
== 1
}
pub fn copy_self_extra(&self) -> Self {
Self {
cumulative: self.cumulative,
..Self::default()
}
}
}
@@ -10,7 +10,7 @@ use crate::utils::get_percentile;
use super::ComputedType;
#[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: VecBuilderOptions,
) -> 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 VecBuilderOptions {
average: bool,
sum: bool,
max: bool,
@@ -721,7 +721,55 @@ pub struct StorableVecGeneatorOptions {
cumulative: bool,
}
impl StorableVecGeneatorOptions {
impl VecBuilderOptions {
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
@@ -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, Source, VecBuilderOptions};
#[derive(Clone)]
pub struct ComputedVecsFromDateIndex<T>
@@ -17,33 +20,37 @@ 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, WeekIndex>,
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex, MonthIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex, QuarterIndex>,
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex, SemesterIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex, YearIndex>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex, DecadeIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromDateIndex<T>
where
T: ComputedType,
T: ComputedType + 'static,
{
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<DateIndex, T>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
indexes: &indexes::Vecs,
options: VecBuilderOptions,
) -> 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 +60,77 @@ 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,
indexes.weekindex_to_weekindex.boxed_clone(),
options.into(),
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
dateindex_source.clone(),
&dateindex_extra,
indexes.monthindex_to_monthindex.boxed_clone(),
options.into(),
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
dateindex_source.clone(),
&dateindex_extra,
indexes.quarterindex_to_quarterindex.boxed_clone(),
options.into(),
)?,
semesterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
Computation::Lazy,
dateindex_source.clone(),
&dateindex_extra,
indexes.semesterindex_to_semesterindex.boxed_clone(),
options.into(),
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
dateindex_source.clone(),
&dateindex_extra,
indexes.yearindex_to_yearindex.boxed_clone(),
options.into(),
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
dateindex_source.clone(),
&dateindex_extra,
indexes.decadeindex_to_decadeindex.boxed_clone(),
options.into(),
)?,
dateindex,
dateindex_extra,
})
}
@@ -133,65 +173,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 +228,7 @@ where
self.weekindex.vecs(),
self.monthindex.vecs(),
self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(),
self.decadeindex.vecs(),
]
@@ -1,16 +1,22 @@
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, CloneableAnyIterableVec, 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, VecBuilderOptions};
#[derive(Clone)]
pub struct ComputedVecsFromHeight<T>
@@ -18,38 +24,41 @@ 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, WeekIndex>,
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex, MonthIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex, QuarterIndex>,
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex, SemesterIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex, YearIndex>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex, DecadeIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromHeight<T>
where
T: ComputedType + Ord + From<f64>,
T: ComputedType + Ord + From<f64> + 'static,
f64: From<T>,
{
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<Height, T>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
indexes: &indexes::Vecs,
options: VecBuilderOptions,
) -> 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 +66,7 @@ where
options.copy_self_extra(),
)?;
let dateindex = ComputedVecBuilder::forced_import(
let dateindex = EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -68,46 +77,77 @@ 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,
indexes.weekindex_to_weekindex.boxed_clone(),
options.into(),
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
None,
&dateindex,
indexes.monthindex_to_monthindex.boxed_clone(),
options.into(),
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
None,
&dateindex,
indexes.quarterindex_to_quarterindex.boxed_clone(),
options.into(),
)?,
semesterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
Computation::Lazy,
None,
&dateindex,
indexes.semesterindex_to_semesterindex.boxed_clone(),
options.into(),
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
None,
&dateindex,
indexes.yearindex_to_yearindex.boxed_clone(),
options.into(),
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
Computation::Lazy,
None,
&dateindex,
indexes.decadeindex_to_decadeindex.boxed_clone(),
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 +229,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 +279,7 @@ where
self.difficultyepoch.vecs(),
self.monthindex.vecs(),
self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(),
// self.halvingepoch.vecs(),
self.decadeindex.vecs(),
@@ -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, VecBuilderOptions};
#[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: VecBuilderOptions,
) -> 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,
@@ -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, CloneableAnyIterableVec, 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, VecBuilderOptions};
#[derive(Clone)]
pub struct ComputedVecsFromTxindex<T>
@@ -20,40 +25,44 @@ 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, WeekIndex>,
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex, MonthIndex>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex, QuarterIndex>,
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex, SemesterIndex>,
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex, YearIndex>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex, DecadeIndex>,
}
const VERSION: Version = Version::ZERO;
impl<T> ComputedVecsFromTxindex<T>
where
T: ComputedType + Ord + From<f64>,
T: ComputedType + Ord + From<f64> + 'static,
f64: From<T>,
{
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
source: Source<TxIndex, T>,
version: Version,
format: Format,
options: StorableVecGeneatorOptions,
computation: Computation,
indexes: &indexes::Vecs,
options: VecBuilderOptions,
) -> 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 +72,86 @@ 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,
indexes.weekindex_to_weekindex.boxed_clone(),
options.into(),
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
None,
&dateindex,
indexes.monthindex_to_monthindex.boxed_clone(),
options.into(),
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
options,
Computation::Lazy,
None,
&dateindex,
indexes.quarterindex_to_quarterindex.boxed_clone(),
options.into(),
)?,
semesterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
Computation::Lazy,
None,
&dateindex,
indexes.semesterindex_to_semesterindex.boxed_clone(),
options.into(),
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
Computation::Lazy,
None,
&dateindex,
indexes.yearindex_to_yearindex.boxed_clone(),
options.into(),
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
format,
Computation::Lazy,
None,
&dateindex,
indexes.decadeindex_to_decadeindex.boxed_clone(),
options.into(),
)?,
txindex,
height,
dateindex,
difficultyepoch: EagerVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
@@ -109,13 +159,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 +239,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 +297,7 @@ where
self.difficultyepoch.vecs(),
self.monthindex.vecs(),
self.quarterindex.vecs(),
self.semesterindex.vecs(),
self.yearindex.vecs(),
// self.halvingepoch.vecs(),
self.decadeindex.vecs(),
+6 -2
View File
@@ -1,21 +1,25 @@
mod builder;
mod builder_computed;
mod builder_eager;
mod from_dateindex;
mod from_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::*;
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,51 @@
use brk_vec::BoxedAnyIterableVec;
#[derive(Clone)]
pub enum Source<I, T> {
Compute,
None,
Vec(BoxedAnyIterableVec<I, T>),
}
impl<I, T> Source<I, T> {
pub fn is_compute(&self) -> bool {
matches!(self, Self::Compute)
}
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
pub fn is_vec(&self) -> bool {
matches!(self, Self::Vec(_))
}
pub fn vec(self) -> Option<BoxedAnyIterableVec<I, T>> {
match self {
Self::Vec(v) => Some(v),
_ => None,
}
}
}
impl<I, T> From<bool> for Source<I, T> {
fn from(value: bool) -> Self {
if value { Self::Compute } else { Self::None }
}
}
impl<I, T> From<BoxedAnyIterableVec<I, T>> for Source<I, T> {
fn from(value: BoxedAnyIterableVec<I, T>) -> Self {
Self::Vec(value)
}
}
impl<I, T> From<Option<BoxedAnyIterableVec<I, T>>> for Source<I, T> {
fn from(value: Option<BoxedAnyIterableVec<I, T>>) -> Self {
if let Some(v) = value {
Self::Vec(v)
} else {
Self::None
}
}
}
+4 -3
View File
@@ -1,13 +1,14 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use brk_vec::StoredType;
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
{
}
@@ -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::{Source, VecBuilderOptions};
#[derive(Clone)]
pub struct ComputedValueVecsFromDateIndex {
@@ -19,39 +19,48 @@ 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: VecBuilderOptions,
compute_dollars: bool,
indexes: &indexes::Vecs,
) -> color_eyre::Result<Self> {
Ok(Self {
sats: ComputedVecsFromDateIndex::forced_import(
path,
name,
compute_source,
source,
version + VERSION,
format,
computation,
indexes,
options,
)?,
bitcoin: ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_in_btc"),
true,
Source::Compute,
version + VERSION,
format,
computation,
indexes,
options,
)?,
dollars: compute_dollars.then(|| {
ComputedVecsFromDateIndex::forced_import(
path,
&format!("{name}_in_usd"),
true,
Source::Compute,
version + VERSION,
format,
computation,
indexes,
options,
)
.unwrap()
@@ -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, VecBuilderOptions};
#[derive(Clone)]
pub struct ComputedValueVecsFromHeight {
@@ -19,39 +19,48 @@ 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: VecBuilderOptions,
compute_dollars: bool,
indexes: &indexes::Vecs,
) -> color_eyre::Result<Self> {
Ok(Self {
sats: ComputedVecsFromHeight::forced_import(
path,
name,
compute_source,
source,
version + VERSION,
format,
computation,
indexes,
options,
)?,
bitcoin: ComputedVecsFromHeight::forced_import(
path,
&format!("{name}_in_btc"),
true,
Source::Compute,
version + VERSION,
format,
computation,
indexes,
options,
)?,
dollars: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&format!("{name}_in_usd"),
true,
Source::Compute,
version + VERSION,
format,
computation,
indexes,
options,
)
.unwrap()
@@ -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, VecBuilderOptions};
#[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: VecBuilderOptions,
) -> 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,20 @@ impl ComputedValueVecsFromTxindex {
let sats = ComputedVecsFromTxindex::forced_import(
path,
name,
compute_source,
source.clone(),
version + VERSION,
format,
computation,
indexes,
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 +81,11 @@ impl ComputedValueVecsFromTxindex {
let bitcoin = ComputedVecsFromTxindex::forced_import(
path,
&name_in_btc,
false,
Source::None,
version + VERSION,
format,
computation,
indexes,
options,
)?;
@@ -124,9 +129,11 @@ impl ComputedValueVecsFromTxindex {
ComputedVecsFromTxindex::forced_import(
path,
&name_in_usd,
false,
Source::None,
version + VERSION,
format,
computation,
indexes,
options,
)
.unwrap()
@@ -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()
}),
+76 -2
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
+17 -8
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, VecBuilderOptions},
indexes,
};
@@ -24,33 +26,40 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
_computation: Computation,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
) -> 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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
path,
"difficultyepoch",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import(
path,
"halvingepoch",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)?,
})
}
+7
View File
@@ -60,6 +60,7 @@ impl Vecs {
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
)
.unwrap()
});
@@ -70,30 +71,35 @@ impl Vecs {
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
)?,
mining: mining::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
)?,
constants: constants::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
)?,
market: market::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
)?,
stateful: stateful::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
fetched.as_ref(),
)?,
transactions: transactions::Vecs::forced_import(
@@ -110,6 +116,7 @@ impl Vecs {
version + VERSION + Version::ZERO,
computation,
format,
&indexes,
fetched.as_ref(),
)?,
indexes,
@@ -11,7 +11,7 @@ use crate::{
states::AddressCohortState,
vecs::{
Indexes, fetched,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
grouped::{ComputedVecsFromHeight, Source, VecBuilderOptions},
indexes, market,
stateful::{
common,
@@ -42,6 +42,7 @@ impl Vecs {
computation: Computation,
format: Format,
version: Version,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
states_path: &Path,
compute_relative_to_all: bool,
@@ -66,10 +67,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
inner: common::Vecs::forced_import(
path,
@@ -77,8 +80,10 @@ impl Vecs {
computation,
format,
version,
indexes,
fetched,
compute_relative_to_all,
false,
)?,
})
}
@@ -10,7 +10,7 @@ use derive_deref::{Deref, DerefMut};
use rayon::prelude::*;
use crate::vecs::{
Indexes, fetched,
Indexes, fetched, indexes,
stateful::{
address_cohort,
r#trait::{CohortVecs, DynCohortVecs},
@@ -28,6 +28,7 @@ impl Vecs {
version: Version,
_computation: Computation,
format: Format,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
states_path: &Path,
) -> color_eyre::Result<Self> {
@@ -40,6 +41,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -50,6 +52,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -60,6 +63,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -70,6 +74,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -80,6 +85,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -90,6 +96,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -100,6 +107,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -110,6 +118,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -120,6 +129,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -130,6 +140,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -140,6 +151,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -150,6 +162,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -160,6 +173,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -170,6 +184,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -180,6 +195,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -192,6 +208,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -202,6 +219,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -212,6 +230,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -222,6 +241,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -232,6 +252,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -242,6 +263,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -252,6 +274,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -262,6 +285,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -272,6 +296,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -282,6 +307,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -292,6 +318,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -302,6 +329,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -312,6 +340,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -324,6 +353,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -334,6 +364,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -344,6 +375,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -354,6 +386,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -364,6 +397,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -374,6 +408,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -384,6 +419,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -394,6 +430,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -404,6 +441,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -414,6 +452,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -424,6 +463,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -434,6 +474,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -444,6 +485,7 @@ impl Vecs {
_computation,
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
states_path,
true,
@@ -0,0 +1,47 @@
use std::{collections::BTreeSet, mem};
use brk_core::TypeIndex;
use derive_deref::{Deref, DerefMut};
use super::ByAddressType;
#[derive(Debug, Deref, DerefMut)]
pub struct AddressTypeToTypeIndexSet(ByAddressType<BTreeSet<TypeIndex>>);
impl AddressTypeToTypeIndexSet {
pub fn merge(mut self, mut other: Self) -> Self {
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
Self::merge_(&mut self.p2sh, &mut other.p2sh);
Self::merge_(&mut self.p2wpkh, &mut other.p2wpkh);
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
Self::merge_(&mut self.p2tr, &mut other.p2tr);
Self::merge_(&mut self.p2a, &mut other.p2a);
self
}
fn merge_(own: &mut BTreeSet<TypeIndex>, other: &mut BTreeSet<TypeIndex>) {
if own.len() >= other.len() {
own.append(other);
} else {
other.append(own);
mem::swap(own, other);
}
}
}
impl Default for AddressTypeToTypeIndexSet {
fn default() -> Self {
Self(ByAddressType {
p2pk65: BTreeSet::default(),
p2pk33: BTreeSet::default(),
p2pkh: BTreeSet::default(),
p2sh: BTreeSet::default(),
p2wpkh: BTreeSet::default(),
p2wsh: BTreeSet::default(),
p2tr: BTreeSet::default(),
p2a: BTreeSet::default(),
})
}
}
@@ -9,7 +9,7 @@ use super::ByAddressType;
pub struct AddressTypeToTypeIndexTree<T>(ByAddressType<BTreeMap<TypeIndex, T>>);
impl<T> AddressTypeToTypeIndexTree<T> {
pub fn merge(&mut self, mut other: Self) {
pub fn merge(mut self, mut other: Self) -> Self {
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
@@ -18,6 +18,7 @@ impl<T> AddressTypeToTypeIndexTree<T> {
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
Self::merge_(&mut self.p2tr, &mut other.p2tr);
Self::merge_(&mut self.p2a, &mut other.p2a);
self
}
fn merge_(own: &mut BTreeMap<TypeIndex, T>, other: &mut BTreeMap<TypeIndex, T>) {
@@ -1,30 +0,0 @@
use std::mem;
use derive_deref::{Deref, DerefMut};
use super::ByAddressType;
#[derive(Debug, Default, Deref, DerefMut)]
pub struct AddressTypeToVec<T>(ByAddressType<Vec<T>>);
impl<T> AddressTypeToVec<T> {
pub fn merge(&mut self, mut other: Self) {
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
Self::merge_(&mut self.p2sh, &mut other.p2sh);
Self::merge_(&mut self.p2wpkh, &mut other.p2wpkh);
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
Self::merge_(&mut self.p2tr, &mut other.p2tr);
Self::merge_(&mut self.p2a, &mut other.p2a);
}
fn merge_(own: &mut Vec<T>, other: &mut Vec<T>) {
if own.len() >= other.len() {
own.append(other);
} else {
other.append(own);
mem::swap(own, other);
}
}
}
@@ -0,0 +1,21 @@
use derive_deref::{Deref, DerefMut};
use super::ByAddressType;
#[derive(Debug, Deref, DerefMut)]
pub struct AddressTypeToVec<T>(ByAddressType<Vec<T>>);
impl<T> Default for AddressTypeToVec<T> {
fn default() -> Self {
Self(ByAddressType {
p2pk65: vec![],
p2pk33: vec![],
p2pkh: vec![],
p2sh: vec![],
p2wpkh: vec![],
p2wsh: vec![],
p2tr: vec![],
p2a: vec![],
})
}
}
+230 -135
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,
Source, VecBuilderOptions,
},
indexes, market,
},
@@ -132,11 +133,13 @@ impl Vecs {
pub fn forced_import(
path: &Path,
cohort_name: Option<&str>,
_computation: Computation,
computation: Computation,
format: Format,
version: Version,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
compute_relative_to_all: bool,
ratio_extended: bool,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
@@ -144,8 +147,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 +207,21 @@ 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,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)
.unwrap()
}),
dateindex_to_supply_in_profit,
height_to_supply_even: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -185,27 +231,21 @@ 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,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)
.unwrap()
}),
dateindex_to_supply_even,
height_to_supply_in_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -215,27 +255,21 @@ 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,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)
.unwrap()
}),
dateindex_to_supply_in_loss,
height_to_unrealized_profit: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -245,26 +279,20 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
dateindex_to_unrealized_profit,
height_to_unrealized_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -292,26 +320,20 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
dateindex_to_unrealized_loss,
height_to_realized_cap: compute_dollars.then(|| {
EagerVec::forced_import(
path,
@@ -325,10 +347,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_cap"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -336,10 +360,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("min_price_paid"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -347,10 +373,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("max_price_paid"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -363,7 +391,7 @@ impl Vecs {
height_to_supply_value: ComputedHeightValueVecs::forced_import(
path,
&suffix("supply"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -371,11 +399,13 @@ impl Vecs {
indexes_to_supply: ComputedValueVecsFromDateIndex::forced_import(
path,
&suffix("supply"),
true,
Source::Compute,
version + VERSION + Version::ONE,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)?,
height_to_utxo_count: EagerVec::forced_import(
path,
@@ -386,19 +416,23 @@ 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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -406,9 +440,12 @@ impl Vecs {
ComputedRatioVecsFromDateIndex::forced_import(
path,
&suffix("realized_price"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
computation,
indexes,
ratio_extended,
)
.unwrap()
}),
@@ -425,10 +462,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_profit"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_sum()
.add_cumulative(),
)
@@ -447,10 +486,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_loss"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_sum()
.add_cumulative(),
)
@@ -460,10 +501,12 @@ 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,
indexes,
VecBuilderOptions::default().add_sum().add_cumulative(),
)
.unwrap()
}),
@@ -480,10 +523,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("value_created"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -491,10 +536,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_value"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -511,10 +558,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("adjusted_value_created"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -531,10 +580,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("value_destroyed"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -551,10 +602,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("adjusted_value_destroyed"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_sum(),
computation,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -562,10 +615,12 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("realized_cap_30d_change"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -573,10 +628,12 @@ impl Vecs {
ComputedVecsFromHeight::forced_import(
path,
&suffix("net_realized_profit_and_loss"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_sum()
.add_cumulative(),
)
@@ -612,7 +669,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,11 +677,13 @@ 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,
VecBuilderOptions::default().add_last(),
compute_dollars,
indexes,
)?,
height_to_negative_unrealized_loss: compute_dollars.then(|| {
EagerVec::forced_import(
@@ -639,10 +698,12 @@ impl Vecs {
ComputedVecsFromDateIndex::forced_import(
path,
&suffix("negative_unrealized_loss"),
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default().add_last(),
computation,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -659,10 +720,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -682,10 +745,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
},
@@ -694,10 +759,12 @@ 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,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -705,10 +772,12 @@ 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,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
}),
@@ -717,10 +786,12 @@ 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,
indexes,
VecBuilderOptions::default().add_sum(),
)
.unwrap()
},
@@ -729,7 +800,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import(
path,
&suffix("supply_even"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -740,7 +811,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import(
path,
&suffix("supply_in_loss"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -751,7 +822,7 @@ impl Vecs {
ComputedHeightValueVecs::forced_import(
path,
&suffix("supply_in_profit"),
false,
Source::None,
version + VERSION + Version::ZERO,
format,
compute_dollars,
@@ -789,10 +860,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -800,10 +873,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -811,10 +886,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -822,10 +899,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -868,10 +947,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -881,10 +962,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -894,10 +977,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)
.unwrap()
}),
@@ -916,27 +1001,33 @@ 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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::default().add_last()
)
.unwrap()
}),
@@ -944,10 +1035,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last()
)
.unwrap()
}),
@@ -955,10 +1048,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last()
)
.unwrap()
}),
@@ -0,0 +1,9 @@
use std::collections::BTreeMap;
use brk_core::Height;
use derive_deref::{Deref, DerefMut};
use crate::vecs::stateful::AddressTypeToVec;
#[derive(Debug, Default, Deref, DerefMut)]
pub struct HeightToAddressTypeToVec<T>(pub BTreeMap<Height, AddressTypeToVec<T>>);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
use std::collections::BTreeMap;
use brk_vec::{IndexedVec, StoredIndex, StoredType};
#[derive(Debug)]
pub struct RangeMap<I, T>(BTreeMap<I, T>);
impl<I, T> RangeMap<I, T>
where
I: StoredIndex,
T: StoredIndex,
{
pub fn get(&self, key: I) -> Option<&T> {
self.0.range(..=key).next_back().map(|(&min, value)| {
if min > key {
unreachable!()
}
value
})
}
}
impl<I, T> From<&IndexedVec<I, T>> for RangeMap<T, I>
where
I: StoredIndex,
T: StoredIndex + StoredType,
{
fn from(vec: &IndexedVec<I, T>) -> Self {
Self(
vec.into_iter()
.map(|(i, v)| (v.into_owned(), i))
.collect::<BTreeMap<_, _>>(),
)
}
}
@@ -33,9 +33,11 @@ impl Vecs {
computation: Computation,
format: Format,
version: Version,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
states_path: &Path,
compute_relative_to_all: bool,
ratio_extended: bool,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
@@ -54,8 +56,10 @@ impl Vecs {
computation,
format,
version,
indexes,
fetched,
compute_relative_to_all,
ratio_extended,
)?,
})
}
File diff suppressed because it is too large Load Diff
+109 -63
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, VecBuilderOptions,
},
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,12 @@ impl Vecs {
indexes_to_tx_count: ComputedVecsFromHeight::forced_import(
path,
"tx_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -352,10 +358,12 @@ impl Vecs {
indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
path,
"input_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -365,10 +373,12 @@ impl Vecs {
indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
path,
"output_count",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -378,43 +388,43 @@ 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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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,
indexes,
VecBuilderOptions::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()
VecBuilderOptions::default()
.add_sum()
.add_cumulative()
.add_percentiles()
@@ -424,10 +434,12 @@ impl Vecs {
indexes_to_feerate: ComputedVecsFromTxindex::forced_import(
path,
"feerate",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -435,10 +447,12 @@ impl Vecs {
indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import(
path,
"tx_vsize",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -446,10 +460,12 @@ impl Vecs {
indexes_to_tx_weight: ComputedVecsFromTxindex::forced_import(
path,
"tx_weight",
false,
Source::None,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -457,49 +473,55 @@ impl Vecs {
indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import(
path,
"subsidy",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
VecBuilderOptions::default()
.add_percentiles()
.add_sum()
.add_cumulative()
.add_minmax()
.add_average(),
compute_dollars,
indexes,
)?,
indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import(
path,
"coinbase",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
VecBuilderOptions::default()
.add_sum()
.add_cumulative()
.add_percentiles()
.add_minmax()
.add_average(),
compute_dollars,
indexes,
)?,
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,
VecBuilderOptions::default().add_sum().add_cumulative(),
compute_dollars,
indexes,
)?,
indexes_to_p2a_count: ComputedVecsFromHeight::forced_import(
path,
"p2a_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -509,10 +531,12 @@ impl Vecs {
indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import(
path,
"p2ms_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -522,10 +546,12 @@ impl Vecs {
indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import(
path,
"p2pk33_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -535,10 +561,12 @@ impl Vecs {
indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import(
path,
"p2pk65_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -548,10 +576,12 @@ impl Vecs {
indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import(
path,
"p2pkh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -561,10 +591,12 @@ impl Vecs {
indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import(
path,
"p2sh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -574,10 +606,12 @@ impl Vecs {
indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import(
path,
"p2tr_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -587,10 +621,12 @@ impl Vecs {
indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import(
path,
"p2wpkh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -600,10 +636,12 @@ impl Vecs {
indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import(
path,
"p2wsh_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -613,10 +651,12 @@ impl Vecs {
indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import(
path,
"opreturn_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -626,10 +666,12 @@ impl Vecs {
indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import(
path,
"unknownoutput_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -639,10 +681,12 @@ impl Vecs {
indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import(
path,
"emptyoutput_count",
true,
Source::Compute,
version + VERSION + Version::ZERO,
format,
StorableVecGeneatorOptions::default()
computation,
indexes,
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
@@ -652,10 +696,12 @@ 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,
indexes,
VecBuilderOptions::default().add_last(),
)?,
txindex_to_is_coinbase,
inputindex_to_value,
+3 -3
View File
@@ -18,15 +18,15 @@ impl AddressData {
}
pub fn realized_price(&self) -> Dollars {
(self.realized_cap / Bitcoin::from(self.amount())).round_nearest_cent()
(self.realized_cap / Bitcoin::from(self.amount())).round_to_4_digits()
}
#[inline(always)]
#[inline]
pub fn has_0_sats(&self) -> bool {
self.amount() == Sats::ZERO
}
#[inline(always)]
#[inline]
pub fn has_0_utxos(&self) -> bool {
self.outputs_len == 0
}
+7 -1
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 {
+18
View File
@@ -24,10 +24,28 @@ use super::Dollars;
)]
pub struct Cents(i64);
const SIGNIFICANT_DIGITS: i32 = 4;
impl Cents {
pub const fn mint(value: i64) -> Self {
Self(value)
}
pub fn round_to_4_digits(self) -> Self {
let v = self.0;
let ilog10 = v.checked_ilog10().unwrap_or(0) as i32;
Self::from(if ilog10 >= SIGNIFICANT_DIGITS {
let log_diff = ilog10 - SIGNIFICANT_DIGITS + 1;
let pow = 10.0_f64.powi(log_diff);
((v as f64 / pow).round() * pow) as i64
} else {
v
})
}
}
impl From<Dollars> for Cents {
+4
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 {
+137 -2
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 - 2) * 7
}
}
fn max_from_(coarser: WeekIndex) -> usize {
let coarser = usize::from(coarser);
if coarser == 0 {
0
} else if coarser == 1 {
3
} else {
3 + (coarser - 1) * 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()
}
}
+37 -1
View File
@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -31,6 +34,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)
@@ -51,6 +66,27 @@ impl Add<usize> for DecadeIndex {
}
}
impl Add<DecadeIndex> for DecadeIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for DecadeIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for DecadeIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<DateIndex> for DecadeIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
@@ -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;
+5 -1
View File
@@ -42,6 +42,10 @@ impl Dollars {
pub fn round_nearest_cent(self) -> Self {
Dollars((self.0 * 100.0).round() / 100.0)
}
pub fn round_to_4_digits(self) -> Self {
Self::from(Cents::from(self).round_to_4_digits())
}
}
impl From<f32> for Dollars {
@@ -239,7 +243,7 @@ impl Mul<Sats> for Dollars {
self
} else {
Self::from(Cents::from(
u128::from(rhs) * u128::from(Cents::from(self)) / u128::from(Sats::ONE_BTC),
u128::from(rhs) * u128::from(Cents::from(self)) / Sats::ONE_BTC_U128,
))
}
}
+7 -1
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 {
+7 -1
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;
+2
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::*;
+31 -1
View File
@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -31,6 +34,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)
@@ -51,6 +60,27 @@ impl Add<usize> for MonthIndex {
}
}
impl Add<MonthIndex> for MonthIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for MonthIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for MonthIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<DateIndex> for MonthIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
+37 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::{Deref, DerefMut};
use 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>,
+31 -1
View File
@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -37,6 +40,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
@@ -51,6 +60,27 @@ impl Add<usize> for QuarterIndex {
}
}
impl Add<QuarterIndex> for QuarterIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for QuarterIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for QuarterIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<MonthIndex> for QuarterIndex {
fn from(value: MonthIndex) -> Self {
Self((usize::from(value) / 3) as u16)
+1
View File
@@ -53,6 +53,7 @@ impl Sats {
pub const ONE_BTC: Self = Self(1_00_000_000);
pub const MAX: Self = Self(u64::MAX);
pub const FIFTY_BTC: Self = Self(50_00_000_000);
pub const ONE_BTC_U128: u128 = 1_00_000_000;
pub fn new(sats: u64) -> Self {
Self(sats)
@@ -0,0 +1,104 @@
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
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 Add<SemesterIndex> for SemesterIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for SemesterIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for SemesterIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<MonthIndex> for SemesterIndex {
fn from(value: MonthIndex) -> Self {
Self((usize::from(value) / 6) as u16)
}
}
impl CheckedSub for SemesterIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for SemesterIndex {
fn to_string() -> &'static str {
"semesterindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["s", "semester", "semesterindex"]
}
}
+7 -1
View File
@@ -1,7 +1,7 @@
use core::panic;
use 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
+7 -1
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
+7 -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;
@@ -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 {
+7 -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;
@@ -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 {
+7 -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;
@@ -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 {
+7 -1
View File
@@ -1,4 +1,4 @@
use std::ops::{Add, Div};
use std::ops::{Add, AddAssign, Div};
use derive_deref::{Deref, DerefMut};
use 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 {
+24 -28
View File
@@ -1,7 +1,4 @@
use std::{
cmp::Ordering,
ops::{Add, Div},
};
use std::ops::{Add, AddAssign, Div};
use derive_deref::Deref;
use jiff::{civil::date, tz::TimeZone};
@@ -29,7 +26,9 @@ use super::Date;
)]
pub struct Timestamp(u32);
const ONE_DAY_IN_SEC: i64 = 24 * 60 * 60;
const ONE_HOUR_IN_SEC: u32 = 60 * 60;
const ONE_DAY_IN_SEC: u32 = 24 * 60 * 60;
const ONE_DAY_IN_SEC_F64: f64 = ONE_DAY_IN_SEC as f64;
impl Timestamp {
pub const ZERO: Self = Self(0);
@@ -50,34 +49,25 @@ impl Timestamp {
Self::from(trunc_date_time.to_zoned(TimeZone::UTC).unwrap().timestamp())
}
pub fn difference_in_days_between(&self, other: Self) -> usize {
match self.cmp(&other) {
Ordering::Equal => 0,
Ordering::Greater => other.difference_in_days_between(*self),
Ordering::Less => {
(jiff::Timestamp::from(*self)
.duration_until(jiff::Timestamp::from(other))
.as_secs()
/ ONE_DAY_IN_SEC) as usize
}
}
#[inline]
pub fn difference_in_days_between(&self, older: Self) -> usize {
// if self.0 < older.0 {
// unreachable!()
// }
((self.0 - older.0) / ONE_DAY_IN_SEC) as usize
}
pub fn difference_in_days_between_float(&self, other: Self) -> f64 {
match self.cmp(&other) {
Ordering::Equal => 0.0,
Ordering::Greater => other.difference_in_days_between_float(*self),
Ordering::Less => {
jiff::Timestamp::from(*self)
.duration_until(jiff::Timestamp::from(other))
.as_secs() as f64
/ ONE_DAY_IN_SEC as f64
}
}
#[inline]
pub fn difference_in_days_between_float(&self, older: Self) -> f64 {
// if self.0 < older.0 {
// unreachable!()
// }
(self.0 - older.0) as f64 / ONE_DAY_IN_SEC_F64
}
#[inline]
pub fn is_more_than_hour(&self) -> bool {
jiff::Timestamp::from(*self).as_second() >= 60 * 60
self.0 >= ONE_HOUR_IN_SEC
}
}
@@ -142,6 +132,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 {
+6
View File
@@ -65,6 +65,12 @@ impl Version {
}
}
impl From<Version> for u64 {
fn from(value: Version) -> u64 {
value.0
}
}
impl From<u64> for Version {
fn from(value: u64) -> Self {
Self(value)
+31 -2
View File
@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -31,6 +34,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)
@@ -43,6 +52,27 @@ impl From<WeekIndex> for usize {
}
}
impl Add<WeekIndex> for WeekIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for WeekIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for WeekIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl Add<usize> for WeekIndex {
type Output = Self;
@@ -68,7 +98,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;
}
+7 -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 {
+25 -1
View File
@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -51,6 +54,27 @@ impl Add<usize> for YearIndex {
}
}
impl Add<YearIndex> for YearIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for YearIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for YearIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<DateIndex> for YearIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
@@ -0,0 +1,18 @@
use std::ops::RangeInclusive;
pub trait FromCoarserIndex<T>
where
T: Ord + From<usize>,
{
fn min_from(coarser: T) -> usize;
fn max_from_(coarser: T) -> usize;
fn max_from(coarser: T, len: usize) -> usize {
Self::max_from_(coarser).min(len - 1)
}
fn inclusive_range_from(coarser: T, len: usize) -> RangeInclusive<usize>
where
T: Clone,
{
Self::min_from(coarser.clone())..=Self::max_from(coarser, len)
}
}
+2
View File
@@ -1,3 +1,5 @@
mod from_coarser;
mod printable;
pub use from_coarser::*;
pub use printable::*;
+1 -1
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,
)?;
+161 -179
View File
@@ -136,34 +136,6 @@ impl Indexer {
vecs.height_to_total_size.push_if_needed(height, block.total_size().into())?;
vecs.height_to_weight.push_if_needed(height, block.weight().into())?;
let inputs = block
.txdata
.iter()
.enumerate()
.flat_map(|(index, tx)| {
tx.input
.iter()
.enumerate()
.map(move |(vin, txin)| (TxIndex::from(index), Vin::from(vin), txin, tx))
})
.collect::<Vec<_>>();
let outputs = block
.txdata
.iter()
.enumerate()
.flat_map(|(index, tx)| {
tx.output
.iter()
.enumerate()
.map(move |(vout, txout)| (TxIndex::from(index), Vout::from(vout), txout, tx))
})
.collect::<Vec<_>>();
let tx_len = block.txdata.len();
let outputs_len = outputs.len();
let inputs_len = inputs.len();
let (
txid_prefix_to_txid_and_block_txindex_and_prev_txindex_join_handle,
input_source_vec_handle,
@@ -173,9 +145,9 @@ impl Indexer {
scope.spawn(|| -> color_eyre::Result<_> {
block
.txdata
.par_iter()
.iter()
.enumerate()
.map(|(index, tx)| -> color_eyre::Result<_> {
.map(|(index, tx)| {
let txid = Txid::from(tx.compute_txid());
let txid_prefix = TxidPrefix::from(&txid);
@@ -190,27 +162,25 @@ impl Indexer {
Ok((txid_prefix, (tx, txid, TxIndex::from(index), prev_txindex_opt)))
})
.try_fold(BTreeMap::new, |mut map, tuple| {
let (key, value) = tuple?;
map.insert(key, value);
Ok(map)
})
.try_reduce(BTreeMap::new, |mut map, mut map2| {
if map.len() > map2.len() {
map.append(&mut map2);
Ok(map)
} else {
map2.append(&mut map);
Ok(map2)
}
})
.collect::<color_eyre::Result<BTreeMap<_, _>>>()
});
let input_source_vec_handle = scope.spawn(|| {
let txindex_to_first_outputindex_mmap = vecs
.txindex_to_first_outputindex.mmap().load();
let inputs = block
.txdata
.iter()
.enumerate()
.flat_map(|(index, tx)| {
tx.input
.iter()
.enumerate()
.map(move |(vin, txin)| (TxIndex::from(index), Vin::from(vin), txin, tx))
})
.collect::<Vec<_>>();
inputs
.into_par_iter()
.enumerate()
@@ -270,157 +240,165 @@ impl Indexer {
})
});
let outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle = scope.spawn(|| {
let p2pk65addressindex_to_p2pk65bytes_mmap = vecs
.p2pk65addressindex_to_p2pk65bytes.mmap().load();
let p2pk33addressindex_to_p2pk33bytes_mmap = vecs.p2pk33addressindex_to_p2pk33bytes.mmap().load();
let p2pkhaddressindex_to_p2pkhbytes_mmap = vecs.p2pkhaddressindex_to_p2pkhbytes.mmap().load();
let p2shaddressindex_to_p2shbytes_mmap = vecs.p2shaddressindex_to_p2shbytes.mmap().load();
let p2wpkhaddressindex_to_p2wpkhbytes_mmap = vecs.p2wpkhaddressindex_to_p2wpkhbytes.mmap().load();
let p2wshaddressindex_to_p2wshbytes_mmap = vecs.p2wshaddressindex_to_p2wshbytes.mmap().load();
let p2traddressindex_to_p2trbytes_mmap = vecs.p2traddressindex_to_p2trbytes.mmap().load();
let p2aaddressindex_to_p2abytes_mmap = vecs.p2aaddressindex_to_p2abytes.mmap().load();
let p2pk65addressindex_to_p2pk65bytes_mmap = vecs
.p2pk65addressindex_to_p2pk65bytes.mmap().load();
let p2pk33addressindex_to_p2pk33bytes_mmap = vecs.p2pk33addressindex_to_p2pk33bytes.mmap().load();
let p2pkhaddressindex_to_p2pkhbytes_mmap = vecs.p2pkhaddressindex_to_p2pkhbytes.mmap().load();
let p2shaddressindex_to_p2shbytes_mmap = vecs.p2shaddressindex_to_p2shbytes.mmap().load();
let p2wpkhaddressindex_to_p2wpkhbytes_mmap = vecs.p2wpkhaddressindex_to_p2wpkhbytes.mmap().load();
let p2wshaddressindex_to_p2wshbytes_mmap = vecs.p2wshaddressindex_to_p2wshbytes.mmap().load();
let p2traddressindex_to_p2trbytes_mmap = vecs.p2traddressindex_to_p2trbytes.mmap().load();
let p2aaddressindex_to_p2abytes_mmap = vecs.p2aaddressindex_to_p2abytes.mmap().load();
outputs
.into_par_iter()
.enumerate()
.map(
#[allow(clippy::type_complexity)]
|(block_outputindex, (block_txindex, vout, txout, tx))| -> color_eyre::Result<(
OutputIndex,
(
&TxOut,
TxIndex,
Vout,
OutputType,
brk_core::Result<AddressBytes>,
Option<TypeIndex>,
&Transaction,
),
)> {
let txindex = idxs.txindex + block_txindex;
let outputindex = idxs.outputindex + OutputIndex::from(block_outputindex);
let outputs = block
.txdata
.iter()
.enumerate()
.flat_map(|(index, tx)| {
tx.output
.iter()
.enumerate()
.map(move |(vout, txout)| (TxIndex::from(index), Vout::from(vout), txout, tx))
}).collect::<Vec<_>>();
let script = &txout.script_pubkey;
let outputindex_to_txout_outputtype_addressbytes_res_addressindex = outputs.into_par_iter()
.enumerate()
.map(
#[allow(clippy::type_complexity)]
|(block_outputindex, (block_txindex, vout, txout, tx))| -> color_eyre::Result<(
OutputIndex,
(
&TxOut,
TxIndex,
Vout,
OutputType,
brk_core::Result<AddressBytes>,
Option<TypeIndex>,
&Transaction,
),
)> {
let txindex = idxs.txindex + block_txindex;
let outputindex = idxs.outputindex + OutputIndex::from(block_outputindex);
let outputtype = OutputType::from(script);
let script = &txout.script_pubkey;
let address_bytes_res =
AddressBytes::try_from((script, outputtype)).inspect_err(|_| {
// dbg!(&txout, height, txi, &tx.compute_txid());
});
let outputtype = OutputType::from(script);
let typeindex_opt = address_bytes_res.as_ref().ok().and_then(|addressbytes| {
stores
.addressbyteshash_to_typeindex
.get(&AddressBytesHash::from((addressbytes, outputtype)))
.unwrap()
.map(|v| *v)
// Checking if not in the future
.and_then(|typeindex_local| {
(typeindex_local < idxs.typeindex(outputtype)).then_some(typeindex_local)
})
let address_bytes_res =
AddressBytes::try_from((script, outputtype)).inspect_err(|_| {
// dbg!(&txout, height, txi, &tx.compute_txid());
});
if let Some(Some(typeindex)) = check_collisions.then_some(typeindex_opt) {
let addressbytes = address_bytes_res.as_ref().unwrap();
let typeindex_opt = address_bytes_res.as_ref().ok().and_then(|addressbytes| {
stores
.addressbyteshash_to_typeindex
.get(&AddressBytesHash::from((addressbytes, outputtype)))
.unwrap()
.map(|v| *v)
// Checking if not in the future
.and_then(|typeindex_local| {
(typeindex_local < idxs.typeindex(outputtype)).then_some(typeindex_local)
})
});
let prev_addressbytes_opt = match outputtype {
OutputType::P2PK65 => vecs
.p2pk65addressindex_to_p2pk65bytes
.get_or_read(typeindex.into(), &p2pk65addressindex_to_p2pk65bytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2PK33 => vecs
.p2pk33addressindex_to_p2pk33bytes
.get_or_read(typeindex.into(), &p2pk33addressindex_to_p2pk33bytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2PKH => vecs
.p2pkhaddressindex_to_p2pkhbytes
.get_or_read(typeindex.into(), &p2pkhaddressindex_to_p2pkhbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2SH => vecs
.p2shaddressindex_to_p2shbytes
.get_or_read(typeindex.into(), &p2shaddressindex_to_p2shbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2WPKH => vecs
.p2wpkhaddressindex_to_p2wpkhbytes
.get_or_read(typeindex.into(), &p2wpkhaddressindex_to_p2wpkhbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2WSH => vecs
.p2wshaddressindex_to_p2wshbytes
.get_or_read(typeindex.into(), &p2wshaddressindex_to_p2wshbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2TR => vecs
.p2traddressindex_to_p2trbytes
.get_or_read(typeindex.into(), &p2traddressindex_to_p2trbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2A => vecs
.p2aaddressindex_to_p2abytes
.get_or_read(typeindex.into(), &p2aaddressindex_to_p2abytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
unreachable!()
}
};
let prev_addressbytes =
prev_addressbytes_opt.as_ref().context("Expect to have addressbytes")?;
if let Some(Some(typeindex)) = check_collisions.then_some(typeindex_opt) {
let addressbytes = address_bytes_res.as_ref().unwrap();
if stores.addressbyteshash_to_typeindex.needs(height)
&& prev_addressbytes != addressbytes
{
let txid = tx.compute_txid();
dbg!(
height,
txid,
vout,
block_txindex,
outputtype,
prev_addressbytes,
addressbytes,
&idxs,
typeindex,
typeindex,
txout,
AddressBytesHash::from((addressbytes, outputtype)),
);
panic!()
let prev_addressbytes_opt = match outputtype {
OutputType::P2PK65 => vecs
.p2pk65addressindex_to_p2pk65bytes
.get_or_read(typeindex.into(), &p2pk65addressindex_to_p2pk65bytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2PK33 => vecs
.p2pk33addressindex_to_p2pk33bytes
.get_or_read(typeindex.into(), &p2pk33addressindex_to_p2pk33bytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2PKH => vecs
.p2pkhaddressindex_to_p2pkhbytes
.get_or_read(typeindex.into(), &p2pkhaddressindex_to_p2pkhbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2SH => vecs
.p2shaddressindex_to_p2shbytes
.get_or_read(typeindex.into(), &p2shaddressindex_to_p2shbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2WPKH => vecs
.p2wpkhaddressindex_to_p2wpkhbytes
.get_or_read(typeindex.into(), &p2wpkhaddressindex_to_p2wpkhbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2WSH => vecs
.p2wshaddressindex_to_p2wshbytes
.get_or_read(typeindex.into(), &p2wshaddressindex_to_p2wshbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2TR => vecs
.p2traddressindex_to_p2trbytes
.get_or_read(typeindex.into(), &p2traddressindex_to_p2trbytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::P2A => vecs
.p2aaddressindex_to_p2abytes
.get_or_read(typeindex.into(), &p2aaddressindex_to_p2abytes_mmap)?
.map(|v| AddressBytes::from(v.into_owned())),
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
unreachable!()
}
}
};
let prev_addressbytes =
prev_addressbytes_opt.as_ref().context("Expect to have addressbytes")?;
Ok((
outputindex,
(
txout,
txindex,
if stores.addressbyteshash_to_typeindex.needs(height)
&& prev_addressbytes != addressbytes
{
let txid = tx.compute_txid();
dbg!(
height,
txid,
vout,
block_txindex,
outputtype,
address_bytes_res,
typeindex_opt,
tx,
),
))
},
)
.try_fold(BTreeMap::new, |mut map, tuple| -> color_eyre::Result<_> {
let (key, value) = tuple?;
map.insert(key, value);
Ok(map)
})
.try_reduce(BTreeMap::new, |mut map, mut map2| {
if map.len() > map2.len() {
map.append(&mut map2);
Ok(map)
} else {
map2.append(&mut map);
Ok(map2)
prev_addressbytes,
addressbytes,
&idxs,
typeindex,
typeindex,
txout,
AddressBytesHash::from((addressbytes, outputtype)),
);
panic!()
}
}
})
});
Ok((
outputindex,
(
txout,
txindex,
vout,
outputtype,
address_bytes_res,
typeindex_opt,
tx,
),
))
},
)
.try_fold(BTreeMap::new, |mut map, tuple| -> color_eyre::Result<_> {
let (key, value) = tuple?;
map.insert(key, value);
Ok(map)
})
.try_reduce(BTreeMap::new, |mut map, mut map2| {
if map.len() > map2.len() {
map.append(&mut map2);
Ok(map)
} else {
map2.append(&mut map);
Ok(map2)
}
});
(
txid_prefix_to_txid_and_block_txindex_and_prev_txindex_handle.join(),
input_source_vec_handle.join(),
outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle.join(),
outputindex_to_txout_outputtype_addressbytes_res_addressindex,
)
});
@@ -440,7 +418,11 @@ impl Indexer {
.ok()
.context(
"Expect outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle to join",
)??;
)?;
let outputs_len = outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt.len();
let inputs_len = input_source_vec.len();
let tx_len = block.txdata.len();
let mut new_txindexvout_to_outputindex: BTreeMap<
(TxIndex, Vout),
+8 -3
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,
+6 -2
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
+1 -1
View File
@@ -14,7 +14,7 @@ use color_eyre::owo_colors::OwoColorize;
use env_logger::{Builder, Env};
use jiff::{Timestamp, tz};
#[inline(always)]
#[inline]
pub fn init(path: Option<&Path>) {
let file = path.map(|path| {
let _ = fs::remove_file(path);
+3 -3
View File
@@ -17,14 +17,14 @@ impl XORIndex {
bytes
}
#[inline(always)]
#[inline]
pub fn byte(&mut self, mut byte: u8, xor_bytes: &XORBytes) -> u8 {
byte ^= xor_bytes[self.0];
self.increment();
byte
}
#[inline(always)]
#[inline]
pub fn increment(&mut self) {
self.0 += 1;
if self.0 == XOR_LEN {
@@ -32,7 +32,7 @@ impl XORIndex {
}
}
#[inline(always)]
#[inline]
pub fn add_assign(&mut self, i: usize) {
self.0 = (self.0 + i) % XOR_LEN;
}
+1 -1
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"]
+4 -1
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()
+6 -6
View File
@@ -8,7 +8,6 @@ use axum::http::{
header::{self, IF_MODIFIED_SINCE, IF_NONE_MATCH},
};
use jiff::{Timestamp, civil::DateTime, fmt::strtime, tz::TimeZone};
use log::info;
const MODIFIED_SINCE_FORMAT: &str = "%a, %d %b %Y %H:%M:%S GMT";
@@ -140,7 +139,11 @@ impl HeaderMapExtended for HeaderMap {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
fn insert_content_type(&mut self, path: &Path) {
match path.extension().unwrap().to_str().unwrap() {
match path
.extension()
.map(|s| s.to_str().unwrap_or_default())
.unwrap_or_default()
{
"js" => self.insert_content_type_application_javascript(),
"json" | "map" => self.insert_content_type_application_json(),
"html" => self.insert_content_type_text_html(),
@@ -152,10 +155,7 @@ impl HeaderMapExtended for HeaderMap {
"jpg" | "jpeg" => self.insert_content_type_image_jpeg(),
"png" => self.insert_content_type_image_png(),
"webmanifest" => self.insert_content_type_application_manifest_json(),
extension => {
info!("Extension unsupported: {extension}");
panic!()
}
_ => {}
}
}
+5 -4
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),
)
}
+6 -2
View File
@@ -22,6 +22,10 @@ where
{
const SIZE_OF_T: usize = size_of::<T>();
#[inline]
fn unwrap_read(&self, index: I, mmap: &Mmap) -> T {
self.read(index, mmap).unwrap().unwrap()
}
#[inline]
fn read(&self, index: I, mmap: &Mmap) -> Result<Option<T>> {
self.read_(index.to_usize()?, mmap)
@@ -122,13 +126,13 @@ where
fn file_write_all(&mut self, file: &mut File, buf: &[u8]) -> Result<()> {
file.write_all(buf)?;
file.flush()?;
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<()>;
+1 -1
View File
@@ -62,7 +62,7 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Cow<'a, Self::T>)> {
fn unwrap_get_inner_(&mut self, i: usize) -> Self::T {
self.get_(i)
.unwrap_or_else(|| {
dbg!(self.name(), i, self.len());
dbg!(self.name(), i, self.len(), Self::I::to_string());
panic!("unwrap_get_inner_")
})
.into_owned()
+2 -2
View File
@@ -120,12 +120,12 @@ where
zstd::encode_all(bytes.as_slice(), DEFAULT_COMPRESSION_LEVEL).unwrap()
}
#[inline(always)]
#[inline]
fn index_to_page_index(index: usize) -> usize {
index / Self::PER_PAGE
}
#[inline(always)]
#[inline]
fn page_index_to_index(page_index: usize) -> usize {
page_index * Self::PER_PAGE
}
+6 -6
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),
+1 -1
View File
@@ -24,7 +24,7 @@ use crate::{
const ONE_KIB: usize = 1024;
const ONE_MIB: usize = ONE_KIB * ONE_KIB;
const MAX_CACHE_SIZE: usize = 210 * ONE_MIB;
const MAX_CACHE_SIZE: usize = 256 * ONE_MIB;
const DCA_AMOUNT: Dollars = Dollars::mint(100.0);
#[derive(Debug, Clone)]
+5
View File
@@ -29,6 +29,11 @@ where
))
}
#[inline]
pub fn unwrap_read(&self, index: I, mmap: &Mmap) -> T {
self.0.unwrap_read(index, mmap)
}
#[inline]
pub fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Cow<T>>> {
self.0.get_or_read(index, mmap)
+2 -2
View File
@@ -35,8 +35,8 @@ 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");
if I::to_string() != S1I::to_string() {
unreachable!()
}
Self {
@@ -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({
+7 -3
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",
+15 -9
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:
+7 -4
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);
}
}