diff --git a/.gitignore b/.gitignore index 0bd55ef7f..3cc4a7322 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ target websites/dist vecid-to-indexes.js +/ids.txt # Copies *\ copy* diff --git a/Cargo.lock b/Cargo.lock index c704843d3..494fe6612 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,9 +451,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.3" +version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" dependencies = [ "serde", ] @@ -608,6 +608,7 @@ dependencies = [ "brk_indexer", "brk_structs", "derive_deref", + "nucleo-matcher", "schemars 1.0.4", "serde", "serde_json", @@ -703,7 +704,7 @@ dependencies = [ "anyhow", "append-only-vec", "arcstr", - "bitflags 2.9.3", + "bitflags 2.9.4", "brk_rolldown_common", "brk_rolldown_debug", "brk_rolldown_ecmascript", @@ -752,7 +753,7 @@ checksum = "23cd66173b33436aaec126f64e8f1d0938539d2eb934e88c633cf6181f7e4c53" dependencies = [ "anyhow", "arcstr", - "bitflags 2.9.3", + "bitflags 2.9.4", "brk_rolldown_ecmascript", "brk_rolldown_error", "brk_rolldown_fs", @@ -834,7 +835,7 @@ checksum = "9fd007c612609bcf46e3dca4f9f3c79d16dc1f0bdf7cd0047bfe752fbc6fbecc" dependencies = [ "anyhow", "arcstr", - "bitflags 2.9.3", + "bitflags 2.9.4", "brk_rolldown_utils", "derive_more", "heck", @@ -865,7 +866,7 @@ dependencies = [ "anyhow", "arcstr", "async-trait", - "bitflags 2.9.3", + "bitflags 2.9.4", "brk_rolldown_common", "brk_rolldown_debug", "brk_rolldown_ecmascript", @@ -1144,10 +1145,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.34" +version = "1.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" +checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3" dependencies = [ + "find-msvc-tools", "jobserver", "libc", "shlex", @@ -1193,18 +1195,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.46" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57" +checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.46" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41" +checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6" dependencies = [ "anstream", "anstyle", @@ -1214,9 +1216,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.45" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" +checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ "heck", "proc-macro2", @@ -1551,9 +1553,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.4.0" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" dependencies = [ "powerfmt", "serde", @@ -1764,6 +1766,12 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "find-msvc-tools" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650" + [[package]] name = "fixedbitset" version = "0.5.7" @@ -2285,7 +2293,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "inotify-sys", "libc", ] @@ -2314,7 +2322,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "cfg-if", "libc", ] @@ -2460,16 +2468,16 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "libc", "redox_syscall", ] [[package]] name = "libz-rs-sys" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "172a788537a2221661b480fee8dc5f96c580eb34fa88764d3205dc356c7e4221" +checksum = "840db8cf39d9ec4dd794376f38acc40d0fc65eec2a8f484f7fd375b84602becd" dependencies = [ "zlib-rs", ] @@ -2609,7 +2617,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "cfg-if", "cfg_aliases", "libc", @@ -2636,7 +2644,7 @@ version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "fsevent-sys", "inotify", "kqueue", @@ -2663,6 +2671,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "nucleo-matcher" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf33f538733d1a5a3494b836ba913207f14d9d4a1d3cd67030c5061bdd2cac85" +dependencies = [ + "memchr", + "unicode-segmentation", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -2816,7 +2834,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "989b81258ce151e23adee6f1393f7c0fb7e10e3a6c6c001f71bbaff4081c72a4" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "oxc_allocator", "oxc_ast_macros", "oxc_data_structures", @@ -2857,7 +2875,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5361ef66f38635d9671596d83abf44bcdbc3e39dbff303f3517828b86ad60e8f" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "itertools", "nonmax", "oxc_index", @@ -2872,7 +2890,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fde8fc6f7337632fce3e9e51c150f57fb0ef234524c6947f63e8009e1ea613cf" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "cow-utils", "dragonbox_ecma", "nonmax", @@ -2950,7 +2968,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83d8c311d64fa0bf8cab1bde3f7760cd828e71ed483ca0878799f1f72542cb4d" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "oxc_allocator", "oxc_ast", "oxc_ast_visit", @@ -3005,7 +3023,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70253728183a5a92d1ba964d9952201e0269ebd07c4917c4553283d564225bab" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "cow-utils", "memchr", "num-bigint", @@ -3028,7 +3046,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de5bb2ed6646bb7815126e0f36787c349e13561fed2c05f95b27a1f82dd066c4" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "oxc_allocator", "oxc_ast_macros", "oxc_diagnostics", @@ -3113,7 +3131,7 @@ version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72d9d80d47d2eee5c1e6dbcdf1841b42afc4f1cd1f63701fc346162616dac52f" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "cow-utils", "dragonbox_ecma", "nonmax", @@ -3621,7 +3639,7 @@ version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", ] [[package]] @@ -3735,7 +3753,7 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ - "bitflags 2.9.3", + "bitflags 2.9.4", "errno", "libc", "linux-raw-sys", @@ -3884,9 +3902,9 @@ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc" [[package]] name = "seqdb" -version = "0.2.5" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54ab988c96efa9d275ca2b12bf2d3c6adec993b8e82ea31a88c984abdaa14fa" +checksum = "ade192d6f8a1e58c43428c8e194016124f20744f75cb14e2fcc0c79309fe4f91" dependencies = [ "libc", "log", @@ -4290,12 +4308,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.41" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" dependencies = [ "deranged", - "itoa", "num-conv", "powerfmt", "serde", @@ -4305,15 +4322,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" [[package]] name = "time-macros" -version = "0.2.22" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" dependencies = [ "num-conv", "time-core", @@ -4444,7 +4461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ "async-compression", - "bitflags 2.9.3", + "bitflags 2.9.4", "bytes", "futures-core", "http", @@ -4616,6 +4633,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "unicode-width" version = "0.2.1" @@ -4672,9 +4695,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ "getrandom 0.3.3", "js-sys", @@ -4712,9 +4735,9 @@ checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23" [[package]] name = "vecdb" -version = "0.2.5" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5c4ec34c376be3a41435eeb7672d0ea0e9c1d60c5d1d90218912588f91abea" +checksum = "5c3e103eeb634851690d815a886ba8fe1ab21d2f520d915c411979bc76de8419" dependencies = [ "ctrlc", "log", @@ -4732,9 +4755,9 @@ dependencies = [ [[package]] name = "vecdb_derive" -version = "0.2.5" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "778c4874c05822465e28cae6a7dead593a73124ec80afb85b85adae5ac883368" +checksum = "6bdf71ae8eeaf2f187cee599e8e34a49bf6fd0536977bd009d94be35e3801754" dependencies = [ "quote", "syn 2.0.106", @@ -5224,9 +5247,9 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626bd9fa9734751fc50d6060752170984d7053f5a39061f524cda68023d4db8a" +checksum = "2f06ae92f42f5e5c42443fd094f245eb656abf56dd7cce9b8b263236565e00f2" [[package]] name = "zopfli" diff --git a/Cargo.toml b/Cargo.toml index 39aa7d075..afdcb9821 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ serde_derive = "1.0.219" serde_json = { version = "1.0.143", features = ["float_roundtrip"] } tokio = { version = "1.47.1", features = ["rt-multi-thread"] } # vecdb = { path = "../seqdb/crates/vecdb", features = ["derive"]} -vecdb = { version = "0.2.5", features = ["derive"]} +vecdb = { version = "0.2.9", features = ["derive"]} zerocopy = "0.8.26" zerocopy-derive = "0.8.26" diff --git a/README.md b/README.md index 033c385c2..bb8159fc7 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Dependency status - + Discord @@ -92,7 +92,3 @@ Heartfelt thanks go out to every donor on [Nostr](https://primal.net/p/npub1jagm ## Donate [`bc1q09 8zsm89 m7kgyz e338vf ejhpdt 92ua9p 3peuve`](bitcoin:bc1q098zsm89m7kgyze338vfejhpdt92ua9p3peuve) - -[`lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhkxmmww3jkuar8d35kgetj8yuq363hv4`](lightning:lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhkxmmww3jkuar8d35kgetj8yuq363hv4) - -[Geyser Fund](https://geyser.fund/project/brk) diff --git a/crates/brk_cli/Cargo.toml b/crates/brk_cli/Cargo.toml index 282f09348..882f49f35 100644 --- a/crates/brk_cli/Cargo.toml +++ b/crates/brk_cli/Cargo.toml @@ -20,8 +20,8 @@ brk_logger = { workspace = true } brk_parser = { workspace = true } brk_server = { workspace = true } vecdb = { workspace = true } -clap = { version = "4.5.46", features = ["string"] } -clap_derive = "4.5.45" +clap = { version = "4.5.47", features = ["string"] } +clap_derive = "4.5.47" color-eyre = "0.6.5" log = { workspace = true } minreq = { workspace = true } diff --git a/crates/brk_computer/src/chain.rs b/crates/brk_computer/src/chain.rs index 4609b3248..850930efc 100644 --- a/crates/brk_computer/src/chain.rs +++ b/crates/brk_computer/src/chain.rs @@ -288,7 +288,7 @@ impl Vecs { let txindex_to_fee_rate = EagerVec::forced_import_compressed(&db, "fee_rate", version + VERSION + Version::ZERO)?; - Ok(Self { + let this = Self { height_to_interval: EagerVec::forced_import_compressed( &db, "interval", @@ -804,7 +804,16 @@ impl Vecs { txindex_to_weight, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } pub fn compute( diff --git a/crates/brk_computer/src/cointime.rs b/crates/brk_computer/src/cointime.rs index 35ee20283..1dbfa6c41 100644 --- a/crates/brk_computer/src/cointime.rs +++ b/crates/brk_computer/src/cointime.rs @@ -43,7 +43,7 @@ pub struct Vecs { pub indexes_to_cointime_price: ComputedVecsFromHeight, pub indexes_to_cointime_cap: ComputedVecsFromHeight, pub indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex, - // pub indexes_to_thermo_cap_relative_to_investor_cap: ComputedValueVecsFromHeight, + // pub indexes_to_thermo_cap_rel_to_investor_cap: ComputedValueVecsFromHeight, } impl Vecs { @@ -58,7 +58,7 @@ impl Vecs { let compute_dollars = price.is_some(); - Ok(Self { + let this = Self { indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import( &db, "coinblocks_created", @@ -247,7 +247,16 @@ impl Vecs { )?, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } #[allow(clippy::too_many_arguments)] @@ -597,7 +606,7 @@ impl Vecs { // The price taken won't be correct for time based indexes vec.compute_multiply( starting_indexes.height, - &price.chainindexes_to_close.height, + &price.chainindexes_to_price_close.height, indexes_to_coinblocks_destroyed.height.as_ref().unwrap(), exit, )?; @@ -613,7 +622,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_multiply( starting_indexes.height, - &price.chainindexes_to_close.height, + &price.chainindexes_to_price_close.height, self.indexes_to_coinblocks_created.height.as_ref().unwrap(), exit, )?; @@ -629,7 +638,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_multiply( starting_indexes.height, - &price.chainindexes_to_close.height, + &price.chainindexes_to_price_close.height, self.indexes_to_coinblocks_stored.height.as_ref().unwrap(), exit, )?; diff --git a/crates/brk_computer/src/constants.rs b/crates/brk_computer/src/constants.rs index 23d034edf..d1b509cc0 100644 --- a/crates/brk_computer/src/constants.rs +++ b/crates/brk_computer/src/constants.rs @@ -38,7 +38,7 @@ impl Vecs { pub fn forced_import(parent: &Path, version: Version, indexes: &indexes::Vecs) -> Result { let db = Database::open(&parent.join("constants"))?; - Ok(Self { + let this = Self { constant_0: ComputedVecsFromHeight::forced_import( &db, "constant_0", @@ -145,7 +145,16 @@ impl Vecs { )?, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } pub fn compute( diff --git a/crates/brk_computer/src/fetched.rs b/crates/brk_computer/src/fetched.rs index b20314f2f..7accefb33 100644 --- a/crates/brk_computer/src/fetched.rs +++ b/crates/brk_computer/src/fetched.rs @@ -16,30 +16,39 @@ pub struct Vecs { db: Database, fetcher: Fetcher, - pub dateindex_to_ohlc_in_cents: RawVec, - pub height_to_ohlc_in_cents: RawVec, + pub dateindex_to_price_ohlc_in_cents: RawVec, + pub height_to_price_ohlc_in_cents: RawVec, } impl Vecs { pub fn forced_import(parent: &Path, fetcher: Fetcher, version: Version) -> Result { let db = Database::open(&parent.join("fetched"))?; - Ok(Self { + let this = Self { fetcher, - dateindex_to_ohlc_in_cents: RawVec::forced_import( + dateindex_to_price_ohlc_in_cents: RawVec::forced_import( &db, - "ohlc_in_cents", + "price_ohlc_in_cents", version + Version::ZERO, )?, - height_to_ohlc_in_cents: RawVec::forced_import( + height_to_price_ohlc_in_cents: RawVec::forced_import( &db, - "ohlc_in_cents", + "price_ohlc_in_cents", version + Version::ZERO, )?, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } pub fn compute( @@ -64,12 +73,12 @@ impl Vecs { let height_to_timestamp = &indexer.vecs.height_to_timestamp; let index = starting_indexes .height - .min(Height::from(self.height_to_ohlc_in_cents.len())); + .min(Height::from(self.height_to_price_ohlc_in_cents.len())); height_to_timestamp .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let v = v.into_owned(); - self.height_to_ohlc_in_cents.forced_push_at( + self.height_to_price_ohlc_in_cents.forced_push_at( i, self.fetcher .get_height( @@ -84,11 +93,11 @@ impl Vecs { )?; Ok(()) })?; - self.height_to_ohlc_in_cents.safe_flush(exit)?; + self.height_to_price_ohlc_in_cents.safe_flush(exit)?; let index = starting_indexes .dateindex - .min(DateIndex::from(self.dateindex_to_ohlc_in_cents.len())); + .min(DateIndex::from(self.dateindex_to_price_ohlc_in_cents.len())); let mut prev = None; indexes .dateindex_to_date @@ -98,7 +107,7 @@ impl Vecs { if prev.is_none() { let i = i.unwrap_to_usize(); prev.replace(if i > 0 { - self.dateindex_to_ohlc_in_cents + self.dateindex_to_price_ohlc_in_cents .into_iter() .unwrap_get_inner_(i - 1) } else { @@ -106,7 +115,8 @@ impl Vecs { }); } - let ohlc = if i.unwrap_to_usize() + 100 >= self.dateindex_to_ohlc_in_cents.len() + let ohlc = if i.unwrap_to_usize() + 100 + >= self.dateindex_to_price_ohlc_in_cents.len() && let Ok(mut ohlc) = self.fetcher.get_date(d) { let prev_open = *prev.as_ref().unwrap().close; @@ -120,20 +130,20 @@ impl Vecs { prev.replace(ohlc.clone()); - self.dateindex_to_ohlc_in_cents + self.dateindex_to_price_ohlc_in_cents .forced_push_at(i, ohlc, exit)?; Ok(()) })?; - self.dateindex_to_ohlc_in_cents.safe_flush(exit)?; + self.dateindex_to_price_ohlc_in_cents.safe_flush(exit)?; Ok(()) } pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { vec![ - &self.dateindex_to_ohlc_in_cents as &dyn AnyCollectableVec, - &self.height_to_ohlc_in_cents, + &self.dateindex_to_price_ohlc_in_cents as &dyn AnyCollectableVec, + &self.height_to_price_ohlc_in_cents, ] } } diff --git a/crates/brk_computer/src/grouped/builder_eager.rs b/crates/brk_computer/src/grouped/builder_eager.rs index ee5022062..05310e3c0 100644 --- a/crates/brk_computer/src/grouped/builder_eager.rs +++ b/crates/brk_computer/src/grouped/builder_eager.rs @@ -144,7 +144,7 @@ where Box::new( EagerVec::forced_import( db, - &suffix("cum"), + &suffix("cumulative"), version + VERSION + Version::ZERO, format, ) diff --git a/crates/brk_computer/src/grouped/builder_lazy.rs b/crates/brk_computer/src/grouped/builder_lazy.rs index 59b9a09c9..3a6bca800 100644 --- a/crates/brk_computer/src/grouped/builder_lazy.rs +++ b/crates/brk_computer/src/grouped/builder_lazy.rs @@ -197,7 +197,7 @@ where }), cumulative: options.cumulative.then(|| { Box::new(LazyVecFrom2::init( - &suffix("cum"), + &suffix("cumulative"), version + VERSION + Version::ZERO, source_extra.cumulative.as_ref().unwrap().boxed_clone(), len_source.clone(), diff --git a/crates/brk_computer/src/grouped/from_txindex.rs b/crates/brk_computer/src/grouped/from_txindex.rs index 89a693378..3780036dd 100644 --- a/crates/brk_computer/src/grouped/from_txindex.rs +++ b/crates/brk_computer/src/grouped/from_txindex.rs @@ -447,7 +447,7 @@ impl ComputedVecsFromTxindex { let starting_index = self.height.starting_index(starting_indexes.height); - let mut close_iter = price.chainindexes_to_close.height.into_iter(); + let mut close_iter = price.chainindexes_to_price_close.height.into_iter(); (starting_index.unwrap_to_usize()..indexer.vecs.height_to_weight.len()) .map(Height::from) diff --git a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs index b4a0f2525..64c354463 100644 --- a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs @@ -22,18 +22,18 @@ pub struct ComputedRatioVecsFromDateIndex { pub ratio: ComputedVecsFromDateIndex, pub ratio_1w_sma: Option>, pub ratio_1m_sma: Option>, - pub ratio_p99: Option>, - pub ratio_p98: Option>, - pub ratio_p95: Option>, - pub ratio_p5: Option>, - pub ratio_p2: Option>, - pub ratio_p1: Option>, - pub ratio_p99_as_price: Option>, - pub ratio_p98_as_price: Option>, - pub ratio_p95_as_price: Option>, - pub ratio_p5_as_price: Option>, - pub ratio_p2_as_price: Option>, - pub ratio_p1_as_price: Option>, + pub ratio_pct99: Option>, + pub ratio_pct98: Option>, + pub ratio_pct95: Option>, + pub ratio_pct5: Option>, + pub ratio_pct2: Option>, + pub ratio_pct1: Option>, + pub ratio_pct99_in_usd: Option>, + pub ratio_pct98_in_usd: Option>, + pub ratio_pct95_in_usd: Option>, + pub ratio_pct5_in_usd: Option>, + pub ratio_pct2_in_usd: Option>, + pub ratio_pct1_in_usd: Option>, pub ratio_sd: Option, pub ratio_4y_sd: Option, @@ -141,10 +141,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p99: extended.then(|| { + ratio_pct99: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p99"), + &format!("{name}_ratio_pct99"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -152,10 +152,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p98: extended.then(|| { + ratio_pct98: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p98"), + &format!("{name}_ratio_pct98"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -163,10 +163,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p95: extended.then(|| { + ratio_pct95: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p95"), + &format!("{name}_ratio_pct95"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -174,10 +174,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p5: extended.then(|| { + ratio_pct5: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p5"), + &format!("{name}_ratio_pct5"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -185,10 +185,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p2: extended.then(|| { + ratio_pct2: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p2"), + &format!("{name}_ratio_pct2"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -196,10 +196,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p1: extended.then(|| { + ratio_pct1: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p1"), + &format!("{name}_ratio_pct1"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -207,10 +207,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p99_as_price: extended.then(|| { + ratio_pct99_in_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p99_as_price"), + &format!("{name}_ratio_pct99_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -218,10 +218,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p98_as_price: extended.then(|| { + ratio_pct98_in_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p98_as_price"), + &format!("{name}_ratio_pct98_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -229,10 +229,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p95_as_price: extended.then(|| { + ratio_pct95_in_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p95_as_price"), + &format!("{name}_ratio_pct95_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -240,10 +240,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p5_as_price: extended.then(|| { + ratio_pct5_in_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p5_as_price"), + &format!("{name}_ratio_pct5_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -251,10 +251,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p2_as_price: extended.then(|| { + ratio_pct2_in_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p2_as_price"), + &format!("{name}_ratio_pct2_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -262,10 +262,10 @@ impl ComputedRatioVecsFromDateIndex { ) .unwrap() }), - ratio_p1_as_price: extended.then(|| { + ratio_pct1_in_usd: extended.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_ratio_p1_as_price"), + &format!("{name}_ratio_pct1_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -322,7 +322,7 @@ impl ComputedRatioVecsFromDateIndex { exit: &Exit, price_opt: Option<&impl AnyIterableVec>, ) -> Result<()> { - let closes = price.timeindexes_to_close.dateindex.as_ref().unwrap(); + let closes = price.timeindexes_to_price_close.dateindex.as_ref().unwrap(); let price = price_opt.unwrap_or_else(|| unsafe { std::mem::transmute(&self.price.as_ref().unwrap().dateindex) @@ -423,42 +423,42 @@ impl ComputedRatioVecsFromDateIndex { .iter_at(starting_dateindex) .try_for_each(|(index, ratio)| -> Result<()> { if index < min_ratio_date { - self.ratio_p5 + self.ratio_pct5 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, StoredF32::NAN, exit)?; - self.ratio_p2 + self.ratio_pct2 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, StoredF32::NAN, exit)?; - self.ratio_p1 + self.ratio_pct1 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, StoredF32::NAN, exit)?; - self.ratio_p95 + self.ratio_pct95 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, StoredF32::NAN, exit)?; - self.ratio_p98 + self.ratio_pct98 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, StoredF32::NAN, exit)?; - self.ratio_p99 + self.ratio_pct99 .as_mut() .unwrap() .dateindex @@ -470,42 +470,42 @@ impl ComputedRatioVecsFromDateIndex { let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos); sorted.insert(pos, ratio); - self.ratio_p1 + self.ratio_pct1 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, get_percentile(&sorted, 0.01), exit)?; - self.ratio_p2 + self.ratio_pct2 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, get_percentile(&sorted, 0.02), exit)?; - self.ratio_p5 + self.ratio_pct5 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, get_percentile(&sorted, 0.05), exit)?; - self.ratio_p95 + self.ratio_pct95 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, get_percentile(&sorted, 0.95), exit)?; - self.ratio_p98 + self.ratio_pct98 .as_mut() .unwrap() .dateindex .as_mut() .unwrap() .forced_push_at(index, get_percentile(&sorted, 0.98), exit)?; - self.ratio_p99 + self.ratio_pct99 .as_mut() .unwrap() .dateindex @@ -521,32 +521,32 @@ impl ComputedRatioVecsFromDateIndex { .into_iter() .try_for_each(|v| v.safe_flush(exit))?; - self.ratio_p1.as_mut().unwrap().compute_rest( + self.ratio_pct1.as_mut().unwrap().compute_rest( starting_indexes, exit, None as Option<&EagerVec<_, _>>, )?; - self.ratio_p2.as_mut().unwrap().compute_rest( + self.ratio_pct2.as_mut().unwrap().compute_rest( starting_indexes, exit, None as Option<&EagerVec<_, _>>, )?; - self.ratio_p5.as_mut().unwrap().compute_rest( + self.ratio_pct5.as_mut().unwrap().compute_rest( starting_indexes, exit, None as Option<&EagerVec<_, _>>, )?; - self.ratio_p95.as_mut().unwrap().compute_rest( + self.ratio_pct95.as_mut().unwrap().compute_rest( starting_indexes, exit, None as Option<&EagerVec<_, _>>, )?; - self.ratio_p98.as_mut().unwrap().compute_rest( + self.ratio_pct98.as_mut().unwrap().compute_rest( starting_indexes, exit, None as Option<&EagerVec<_, _>>, )?; - self.ratio_p99.as_mut().unwrap().compute_rest( + self.ratio_pct99.as_mut().unwrap().compute_rest( starting_indexes, exit, None as Option<&EagerVec<_, _>>, @@ -556,14 +556,14 @@ impl ComputedRatioVecsFromDateIndex { std::mem::transmute(&self.price.as_ref().unwrap().dateindex) }); - self.ratio_p99_as_price.as_mut().unwrap().compute_all( + self.ratio_pct99_in_usd.as_mut().unwrap().compute_all( indexer, indexes, starting_indexes, exit, |vec, _, _, starting_indexes, exit| { let mut iter = self - .ratio_p99 + .ratio_pct99 .as_ref() .unwrap() .dateindex @@ -583,10 +583,10 @@ impl ComputedRatioVecsFromDateIndex { }, )?; - let compute_as_price = - |as_price: Option<&mut ComputedVecsFromDateIndex>, + let compute_in_usd = + |in_usd: Option<&mut ComputedVecsFromDateIndex>, source: Option<&ComputedVecsFromDateIndex>| { - as_price.unwrap().compute_all( + in_usd.unwrap().compute_all( indexer, indexes, starting_indexes, @@ -607,12 +607,12 @@ impl ComputedRatioVecsFromDateIndex { ) }; - compute_as_price(self.ratio_p1_as_price.as_mut(), self.ratio_p1.as_ref())?; - compute_as_price(self.ratio_p2_as_price.as_mut(), self.ratio_p2.as_ref())?; - compute_as_price(self.ratio_p5_as_price.as_mut(), self.ratio_p5.as_ref())?; - compute_as_price(self.ratio_p95_as_price.as_mut(), self.ratio_p95.as_ref())?; - compute_as_price(self.ratio_p98_as_price.as_mut(), self.ratio_p98.as_ref())?; - compute_as_price(self.ratio_p99_as_price.as_mut(), self.ratio_p99.as_ref())?; + compute_in_usd(self.ratio_pct1_in_usd.as_mut(), self.ratio_pct1.as_ref())?; + compute_in_usd(self.ratio_pct2_in_usd.as_mut(), self.ratio_pct2.as_ref())?; + compute_in_usd(self.ratio_pct5_in_usd.as_mut(), self.ratio_pct5.as_ref())?; + compute_in_usd(self.ratio_pct95_in_usd.as_mut(), self.ratio_pct95.as_ref())?; + compute_in_usd(self.ratio_pct98_in_usd.as_mut(), self.ratio_pct98.as_ref())?; + compute_in_usd(self.ratio_pct99_in_usd.as_mut(), self.ratio_pct99.as_ref())?; self.ratio_sd.as_mut().unwrap().compute_all( indexer, @@ -652,22 +652,22 @@ impl ComputedRatioVecsFromDateIndex { fn mut_ratio_vecs(&mut self) -> Vec<&mut EagerVec> { [ - self.ratio_p1 + self.ratio_pct1 .as_mut() .map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]), - self.ratio_p2 + self.ratio_pct2 .as_mut() .map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]), - self.ratio_p5 + self.ratio_pct5 .as_mut() .map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]), - self.ratio_p95 + self.ratio_pct95 .as_mut() .map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]), - self.ratio_p98 + self.ratio_pct98 .as_mut() .map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]), - self.ratio_p99 + self.ratio_pct99 .as_mut() .map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]), ] @@ -686,22 +686,22 @@ impl ComputedRatioVecsFromDateIndex { self.ratio_1y_sd.as_ref().map_or(vec![], |v| v.vecs()), self.ratio_2y_sd.as_ref().map_or(vec![], |v| v.vecs()), self.ratio_4y_sd.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p1.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p2.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p5.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p95.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p98.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p99.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p1_as_price.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p2_as_price.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p5_as_price.as_ref().map_or(vec![], |v| v.vecs()), - self.ratio_p95_as_price + self.ratio_pct1.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct2.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct5.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct95.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct98.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct99.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct1_in_usd.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct2_in_usd.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct5_in_usd.as_ref().map_or(vec![], |v| v.vecs()), + self.ratio_pct95_in_usd .as_ref() .map_or(vec![], |v| v.vecs()), - self.ratio_p98_as_price + self.ratio_pct98_in_usd .as_ref() .map_or(vec![], |v| v.vecs()), - self.ratio_p99_as_price + self.ratio_pct99_in_usd .as_ref() .map_or(vec![], |v| v.vecs()), ] diff --git a/crates/brk_computer/src/grouped/sd_from_dateindex.rs b/crates/brk_computer/src/grouped/sd_from_dateindex.rs index 1e957d147..3148d4193 100644 --- a/crates/brk_computer/src/grouped/sd_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/sd_from_dateindex.rs @@ -16,7 +16,7 @@ pub struct ComputedStandardDeviationVecsFromDateIndex { pub sma: Option>, pub sd: ComputedVecsFromDateIndex, - pub _0sd_as_price: ComputedVecsFromDateIndex, + pub _0sd_in_usd: ComputedVecsFromDateIndex, pub p0_5sd: ComputedVecsFromDateIndex, pub p1sd: ComputedVecsFromDateIndex, pub p1_5sd: ComputedVecsFromDateIndex, @@ -29,18 +29,18 @@ pub struct ComputedStandardDeviationVecsFromDateIndex { pub m2sd: ComputedVecsFromDateIndex, pub m2_5sd: ComputedVecsFromDateIndex, pub m3sd: ComputedVecsFromDateIndex, - pub p0_5sd_as_price: ComputedVecsFromDateIndex, - pub p1sd_as_price: ComputedVecsFromDateIndex, - pub p1_5sd_as_price: ComputedVecsFromDateIndex, - pub p2sd_as_price: ComputedVecsFromDateIndex, - pub p2_5sd_as_price: ComputedVecsFromDateIndex, - pub p3sd_as_price: ComputedVecsFromDateIndex, - pub m0_5sd_as_price: ComputedVecsFromDateIndex, - pub m1sd_as_price: ComputedVecsFromDateIndex, - pub m1_5sd_as_price: ComputedVecsFromDateIndex, - pub m2sd_as_price: ComputedVecsFromDateIndex, - pub m2_5sd_as_price: ComputedVecsFromDateIndex, - pub m3sd_as_price: ComputedVecsFromDateIndex, + pub p0_5sd_in_usd: ComputedVecsFromDateIndex, + pub p1sd_in_usd: ComputedVecsFromDateIndex, + pub p1_5sd_in_usd: ComputedVecsFromDateIndex, + pub p2sd_in_usd: ComputedVecsFromDateIndex, + pub p2_5sd_in_usd: ComputedVecsFromDateIndex, + pub p3sd_in_usd: ComputedVecsFromDateIndex, + pub m0_5sd_in_usd: ComputedVecsFromDateIndex, + pub m1sd_in_usd: ComputedVecsFromDateIndex, + pub m1_5sd_in_usd: ComputedVecsFromDateIndex, + pub m2sd_in_usd: ComputedVecsFromDateIndex, + pub m2_5sd_in_usd: ComputedVecsFromDateIndex, + pub m3sd_in_usd: ComputedVecsFromDateIndex, pub zscore: ComputedVecsFromDateIndex, } @@ -175,105 +175,105 @@ impl ComputedStandardDeviationVecsFromDateIndex { indexes, options, )?, - _0sd_as_price: ComputedVecsFromDateIndex::forced_import( + _0sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_0sd_as_price"), + &format!("{name}_0sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - p0_5sd_as_price: ComputedVecsFromDateIndex::forced_import( + p0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p0_5sd_as_price"), + &format!("{name}_p0_5sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - p1sd_as_price: ComputedVecsFromDateIndex::forced_import( + p1sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p1sd_as_price"), + &format!("{name}_p1sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - p1_5sd_as_price: ComputedVecsFromDateIndex::forced_import( + p1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p1_5sd_as_price"), + &format!("{name}_p1_5sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - p2sd_as_price: ComputedVecsFromDateIndex::forced_import( + p2sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p2sd_as_price"), + &format!("{name}_p2sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - p2_5sd_as_price: ComputedVecsFromDateIndex::forced_import( + p2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p2_5sd_as_price"), + &format!("{name}_p2_5sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - p3sd_as_price: ComputedVecsFromDateIndex::forced_import( + p3sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_p3sd_as_price"), + &format!("{name}_p3sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - m0_5sd_as_price: ComputedVecsFromDateIndex::forced_import( + m0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m0_5sd_as_price"), + &format!("{name}_m0_5sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - m1sd_as_price: ComputedVecsFromDateIndex::forced_import( + m1sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m1sd_as_price"), + &format!("{name}_m1sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - m1_5sd_as_price: ComputedVecsFromDateIndex::forced_import( + m1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m1_5sd_as_price"), + &format!("{name}_m1_5sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - m2sd_as_price: ComputedVecsFromDateIndex::forced_import( + m2sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m2sd_as_price"), + &format!("{name}_m2sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - m2_5sd_as_price: ComputedVecsFromDateIndex::forced_import( + m2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m2_5sd_as_price"), + &format!("{name}_m2_5sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, options, )?, - m3sd_as_price: ComputedVecsFromDateIndex::forced_import( + m3sd_in_usd: ComputedVecsFromDateIndex::forced_import( db, - &format!("{name}_m3sd_as_price"), + &format!("{name}_m3sd_in_usd"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -297,7 +297,7 @@ impl ComputedStandardDeviationVecsFromDateIndex { starting_indexes: &Indexes, exit: &Exit, source: &impl CollectableVec, - source_as_price: Option<&impl AnyIterableVec>, + source_in_usd: Option<&impl AnyIterableVec>, ) -> Result<()> { let min_date = DateIndex::try_from(Date::MIN_RATIO).unwrap(); @@ -326,7 +326,7 @@ impl ComputedStandardDeviationVecsFromDateIndex { exit, sma_opt, source, - source_as_price, + source_in_usd, ) } @@ -339,7 +339,7 @@ impl ComputedStandardDeviationVecsFromDateIndex { exit: &Exit, sma_opt: Option<&impl AnyIterableVec>, source: &impl CollectableVec, - source_as_price: Option<&impl AnyIterableVec>, + source_in_usd: Option<&impl AnyIterableVec>, ) -> Result<()> { let sma = sma_opt.unwrap_or_else(|| unsafe { std::mem::transmute(&self.sma.as_ref().unwrap().dateindex) @@ -571,14 +571,14 @@ impl ComputedStandardDeviationVecsFromDateIndex { }, )?; - let Some(price) = source_as_price else { + let Some(price) = source_in_usd else { return Ok(()); }; - let compute_as_price = - |as_price: &mut ComputedVecsFromDateIndex, + let compute_in_usd = + |in_usd: &mut ComputedVecsFromDateIndex, mut iter: BoxedVecIterator| { - as_price.compute_all( + in_usd.compute_all( indexer, indexes, starting_indexes, @@ -598,53 +598,53 @@ impl ComputedStandardDeviationVecsFromDateIndex { ) }; - compute_as_price(&mut self._0sd_as_price, sma.iter())?; - compute_as_price( - &mut self.p0_5sd_as_price, + compute_in_usd(&mut self._0sd_in_usd, sma.iter())?; + compute_in_usd( + &mut self.p0_5sd_in_usd, self.p0_5sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.p1sd_as_price, + compute_in_usd( + &mut self.p1sd_in_usd, self.p1sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.p1_5sd_as_price, + compute_in_usd( + &mut self.p1_5sd_in_usd, self.p1_5sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.p2sd_as_price, + compute_in_usd( + &mut self.p2sd_in_usd, self.p2sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.p2_5sd_as_price, + compute_in_usd( + &mut self.p2_5sd_in_usd, self.p2_5sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.p3sd_as_price, + compute_in_usd( + &mut self.p3sd_in_usd, self.p3sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.m0_5sd_as_price, + compute_in_usd( + &mut self.m0_5sd_in_usd, self.m0_5sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.m1sd_as_price, + compute_in_usd( + &mut self.m1sd_in_usd, self.m1sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.m1_5sd_as_price, + compute_in_usd( + &mut self.m1_5sd_in_usd, self.m1_5sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.m2sd_as_price, + compute_in_usd( + &mut self.m2sd_in_usd, self.m2sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.m2_5sd_as_price, + compute_in_usd( + &mut self.m2_5sd_in_usd, self.m2_5sd.dateindex.as_ref().unwrap().iter(), )?; - compute_as_price( - &mut self.m3sd_as_price, + compute_in_usd( + &mut self.m3sd_in_usd, self.m3sd.dateindex.as_ref().unwrap().iter(), )?; @@ -685,19 +685,19 @@ impl ComputedStandardDeviationVecsFromDateIndex { self.m2sd.vecs(), self.m2_5sd.vecs(), self.m3sd.vecs(), - self._0sd_as_price.vecs(), - self.p0_5sd_as_price.vecs(), - self.p1sd_as_price.vecs(), - self.p1_5sd_as_price.vecs(), - self.p2sd_as_price.vecs(), - self.p2_5sd_as_price.vecs(), - self.p3sd_as_price.vecs(), - self.m0_5sd_as_price.vecs(), - self.m1sd_as_price.vecs(), - self.m1_5sd_as_price.vecs(), - self.m2sd_as_price.vecs(), - self.m2_5sd_as_price.vecs(), - self.m3sd_as_price.vecs(), + self._0sd_in_usd.vecs(), + self.p0_5sd_in_usd.vecs(), + self.p1sd_in_usd.vecs(), + self.p1_5sd_in_usd.vecs(), + self.p2sd_in_usd.vecs(), + self.p2_5sd_in_usd.vecs(), + self.p3sd_in_usd.vecs(), + self.m0_5sd_in_usd.vecs(), + self.m1sd_in_usd.vecs(), + self.m1_5sd_in_usd.vecs(), + self.m2sd_in_usd.vecs(), + self.m2_5sd_in_usd.vecs(), + self.m3sd_in_usd.vecs(), self.zscore.vecs(), ] .into_iter() diff --git a/crates/brk_computer/src/grouped/value_from_dateindex.rs b/crates/brk_computer/src/grouped/value_from_dateindex.rs index 24307ba63..31f342243 100644 --- a/crates/brk_computer/src/grouped/value_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/value_from_dateindex.rs @@ -138,10 +138,10 @@ impl ComputedValueVecsFromDateIndex { } let dateindex_to_bitcoin = self.bitcoin.dateindex.as_ref().unwrap(); - let dateindex_to_close = price + let dateindex_to_price_close = price .as_ref() .unwrap() - .timeindexes_to_close + .timeindexes_to_price_close .dateindex .as_ref() .unwrap(); @@ -156,7 +156,7 @@ impl ComputedValueVecsFromDateIndex { v.compute_from_bitcoin( starting_indexes.dateindex, dateindex_to_bitcoin, - dateindex_to_close, + dateindex_to_price_close, exit, ) }, diff --git a/crates/brk_computer/src/grouped/value_from_height.rs b/crates/brk_computer/src/grouped/value_from_height.rs index 63c2135b2..d38a2b88e 100644 --- a/crates/brk_computer/src/grouped/value_from_height.rs +++ b/crates/brk_computer/src/grouped/value_from_height.rs @@ -139,7 +139,7 @@ impl ComputedValueVecsFromHeight { } let height_to_bitcoin = self.bitcoin.height.as_ref().unwrap(); - let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height; + let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height; if let Some(dollars) = self.dollars.as_mut() { dollars.compute_all( @@ -151,7 +151,7 @@ impl ComputedValueVecsFromHeight { v.compute_from_bitcoin( starting_indexes.height, height_to_bitcoin, - height_to_close, + height_to_price_close, exit, ) }, diff --git a/crates/brk_computer/src/grouped/value_from_txindex.rs b/crates/brk_computer/src/grouped/value_from_txindex.rs index 0a3ee5210..ed3a7fa3a 100644 --- a/crates/brk_computer/src/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/grouped/value_from_txindex.rs @@ -78,23 +78,25 @@ impl ComputedValueVecsFromTxindex { version + VERSION, bitcoin_txindex.boxed_clone(), indexes.txindex_to_height.boxed_clone(), - price.chainindexes_to_close.height.boxed_clone(), + price.chainindexes_to_price_close.height.boxed_clone(), |txindex: TxIndex, - txindex_to_btc_iter, + txindex_to_in_btc_iter, txindex_to_height_iter, - height_to_close_iter| { + height_to_price_close_iter| { let txindex = txindex.unwrap_to_usize(); - txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| { - let btc = value.into_owned(); - txindex_to_height_iter - .next_at(txindex) - .and_then(|(_, value)| { - let height = value.into_owned(); - height_to_close_iter - .next_at(height.unwrap_to_usize()) - .map(|(_, close)| *close.into_owned() * btc) - }) - }) + txindex_to_in_btc_iter + .next_at(txindex) + .and_then(|(_, value)| { + let btc = value.into_owned(); + txindex_to_height_iter + .next_at(txindex) + .and_then(|(_, value)| { + let height = value.into_owned(); + height_to_price_close_iter + .next_at(height.unwrap_to_usize()) + .map(|(_, close)| *close.into_owned() * btc) + }) + }) }, ) }); diff --git a/crates/brk_computer/src/grouped/value_height.rs b/crates/brk_computer/src/grouped/value_height.rs index ff6281d54..3fab71737 100644 --- a/crates/brk_computer/src/grouped/value_height.rs +++ b/crates/brk_computer/src/grouped/value_height.rs @@ -102,13 +102,13 @@ impl ComputedHeightValueVecs { } let height_to_bitcoin = &self.bitcoin; - let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height; + let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height; if let Some(dollars) = self.dollars.as_mut() { dollars.compute_from_bitcoin( starting_indexes.height, height_to_bitcoin, - height_to_close, + height_to_price_close, exit, )?; } diff --git a/crates/brk_computer/src/indexes.rs b/crates/brk_computer/src/indexes.rs index 671821374..3b77c44c2 100644 --- a/crates/brk_computer/src/indexes.rs +++ b/crates/brk_computer/src/indexes.rs @@ -236,7 +236,7 @@ impl Vecs { |index, _| Some(index), ); - Ok(Self { + let this = Self { emptyoutputindex_to_emptyoutputindex, inputindex_to_inputindex, opreturnindex_to_opreturnindex, @@ -472,7 +472,16 @@ impl Vecs { )?, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } pub fn compute( diff --git a/crates/brk_computer/src/market.rs b/crates/brk_computer/src/market.rs index c1f3738f2..64140712e 100644 --- a/crates/brk_computer/src/market.rs +++ b/crates/brk_computer/src/market.rs @@ -23,46 +23,46 @@ const VERSION: Version = Version::ZERO; pub struct Vecs { db: Database, - pub height_to_ath: EagerVec, - pub height_to_drawdown: EagerVec, - pub indexes_to_ath: ComputedVecsFromDateIndex, - pub indexes_to_drawdown: ComputedVecsFromDateIndex, - pub indexes_to_days_since_ath: ComputedVecsFromDateIndex, - pub indexes_to_max_days_between_aths: ComputedVecsFromDateIndex, - pub indexes_to_max_years_between_aths: ComputedVecsFromDateIndex, + pub height_to_price_ath: EagerVec, + pub height_to_price_drawdown: EagerVec, + pub indexes_to_price_ath: ComputedVecsFromDateIndex, + pub indexes_to_price_drawdown: ComputedVecsFromDateIndex, + pub indexes_to_days_since_price_ath: ComputedVecsFromDateIndex, + pub indexes_to_max_days_between_price_aths: ComputedVecsFromDateIndex, + pub indexes_to_max_years_between_price_aths: ComputedVecsFromDateIndex, - pub indexes_to_1w_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_8d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_13d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_21d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_1m_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_34d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_55d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_89d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_144d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_200d_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_1y_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_2y_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_200w_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_4y_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_1w_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_8d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_13d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_21d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_1m_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_34d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_55d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_89d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_144d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_200d_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_1y_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_2y_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_200w_sma: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_4y_sma: ComputedRatioVecsFromDateIndex, - pub indexes_to_1w_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_8d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_13d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_21d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_1m_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_34d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_55d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_89d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_144d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_200d_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_1y_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_2y_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_200w_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_4y_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_1w_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_8d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_13d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_21d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_1m_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_34d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_55d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_89d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_144d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_200d_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_1y_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_2y_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_200w_ema: ComputedRatioVecsFromDateIndex, + pub indexes_to_price_4y_ema: ComputedRatioVecsFromDateIndex, - pub indexes_to_200d_sma_x2_4: ComputedVecsFromDateIndex, - pub indexes_to_200d_sma_x0_8: ComputedVecsFromDateIndex, + pub indexes_to_price_200d_sma_x2_4: ComputedVecsFromDateIndex, + pub indexes_to_price_200d_sma_x0_8: ComputedVecsFromDateIndex, pub price_1d_ago: ComputedVecsFromDateIndex, pub price_1w_ago: ComputedVecsFromDateIndex, @@ -78,19 +78,19 @@ pub struct Vecs { pub price_8y_ago: ComputedVecsFromDateIndex, pub price_10y_ago: ComputedVecsFromDateIndex, - pub _1d_returns: ComputedVecsFromDateIndex, - pub _1w_returns: ComputedVecsFromDateIndex, - pub _1m_returns: ComputedVecsFromDateIndex, - pub _3m_returns: ComputedVecsFromDateIndex, - pub _6m_returns: ComputedVecsFromDateIndex, - pub _1y_returns: ComputedVecsFromDateIndex, - pub _2y_returns: ComputedVecsFromDateIndex, - pub _3y_returns: ComputedVecsFromDateIndex, - pub _4y_returns: ComputedVecsFromDateIndex, - pub _5y_returns: ComputedVecsFromDateIndex, - pub _6y_returns: ComputedVecsFromDateIndex, - pub _8y_returns: ComputedVecsFromDateIndex, - pub _10y_returns: ComputedVecsFromDateIndex, + pub _1d_price_returns: ComputedVecsFromDateIndex, + pub _1w_price_returns: ComputedVecsFromDateIndex, + pub _1m_price_returns: ComputedVecsFromDateIndex, + pub _3m_price_returns: ComputedVecsFromDateIndex, + pub _6m_price_returns: ComputedVecsFromDateIndex, + pub _1y_price_returns: ComputedVecsFromDateIndex, + pub _2y_price_returns: ComputedVecsFromDateIndex, + pub _3y_price_returns: ComputedVecsFromDateIndex, + pub _4y_price_returns: ComputedVecsFromDateIndex, + pub _5y_price_returns: ComputedVecsFromDateIndex, + pub _6y_price_returns: ComputedVecsFromDateIndex, + pub _8y_price_returns: ComputedVecsFromDateIndex, + pub _10y_price_returns: ComputedVecsFromDateIndex, pub _2y_cagr: ComputedVecsFromDateIndex, pub _3y_cagr: ComputedVecsFromDateIndex, pub _4y_cagr: ComputedVecsFromDateIndex, @@ -185,383 +185,383 @@ impl Vecs { let db = Database::open(&parent.join("market"))?; db.set_min_len(PAGE_SIZE * 1_000_000)?; - Ok(Self { - height_to_ath: EagerVec::forced_import_compressed( + let this = Self { + height_to_price_ath: EagerVec::forced_import_compressed( &db, - "ath", + "price_ath", version + VERSION + Version::ZERO, )?, - height_to_drawdown: EagerVec::forced_import_compressed( + height_to_price_drawdown: EagerVec::forced_import_compressed( &db, - "drawdown", + "price_drawdown", version + VERSION + Version::ZERO, )?, - indexes_to_ath: ComputedVecsFromDateIndex::forced_import( + indexes_to_price_ath: ComputedVecsFromDateIndex::forced_import( &db, - "ath", + "price_ath", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_drawdown: ComputedVecsFromDateIndex::forced_import( + indexes_to_price_drawdown: ComputedVecsFromDateIndex::forced_import( &db, - "drawdown", + "price_drawdown", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_days_since_ath: ComputedVecsFromDateIndex::forced_import( + indexes_to_days_since_price_ath: ComputedVecsFromDateIndex::forced_import( &db, - "days_since_ath", + "days_since_price_ath", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_max_days_between_aths: ComputedVecsFromDateIndex::forced_import( + indexes_to_max_days_between_price_aths: ComputedVecsFromDateIndex::forced_import( &db, - "max_days_between_aths", + "max_days_between_price_aths", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_max_years_between_aths: ComputedVecsFromDateIndex::forced_import( + indexes_to_max_years_between_price_aths: ComputedVecsFromDateIndex::forced_import( &db, - "max_years_between_aths", + "max_years_between_price_aths", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_1w_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_1w_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "1w_sma", + "price_1w_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_8d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_8d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "8d_sma", + "price_8d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_13d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_13d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "13d_sma", + "price_13d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_21d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_21d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "21d_sma", + "price_21d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_1m_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_1m_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "1m_sma", + "price_1m_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_34d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_34d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "34d_sma", + "price_34d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_55d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_55d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "55d_sma", + "price_55d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_89d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_89d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "89d_sma", + "price_89d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_144d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_144d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "144d_sma", + "price_144d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_200d_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_200d_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "200d_sma", + "price_200d_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_1y_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_1y_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "1y_sma", + "price_1y_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_2y_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_2y_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "2y_sma", + "price_2y_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_200w_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_200w_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "200w_sma", + "price_200w_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_4y_sma: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_4y_sma: ComputedRatioVecsFromDateIndex::forced_import( &db, - "4y_sma", + "price_4y_sma", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_1w_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_1w_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "1w_ema", + "price_1w_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_8d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_8d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "8d_ema", + "price_8d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_13d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_13d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "13d_ema", + "price_13d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_21d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_21d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "21d_ema", + "price_21d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_1m_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_1m_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "1m_ema", + "price_1m_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_34d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_34d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "34d_ema", + "price_34d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_55d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_55d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "55d_ema", + "price_55d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_89d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_89d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "89d_ema", + "price_89d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_144d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_144d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "144d_ema", + "price_144d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_200d_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_200d_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "200d_ema", + "price_200d_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_1y_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_1y_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "1y_ema", + "price_1y_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_2y_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_2y_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "2y_ema", + "price_2y_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_200w_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_200w_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "200w_ema", + "price_200w_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - indexes_to_4y_ema: ComputedRatioVecsFromDateIndex::forced_import( + indexes_to_price_4y_ema: ComputedRatioVecsFromDateIndex::forced_import( &db, - "4y_ema", + "price_4y_ema", Source::Compute, version + VERSION + Version::ZERO, indexes, true, )?, - _1d_returns: ComputedVecsFromDateIndex::forced_import( + _1d_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "1d_returns", + "1d_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _1w_returns: ComputedVecsFromDateIndex::forced_import( + _1w_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "1w_returns", + "1w_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _1m_returns: ComputedVecsFromDateIndex::forced_import( + _1m_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "1m_returns", + "1m_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _3m_returns: ComputedVecsFromDateIndex::forced_import( + _3m_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "3m_returns", + "3m_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _6m_returns: ComputedVecsFromDateIndex::forced_import( + _6m_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "6m_returns", + "6m_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _1y_returns: ComputedVecsFromDateIndex::forced_import( + _1y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "1y_returns", + "1y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _2y_returns: ComputedVecsFromDateIndex::forced_import( + _2y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "2y_returns", + "2y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _3y_returns: ComputedVecsFromDateIndex::forced_import( + _3y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "3y_returns", + "3y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _4y_returns: ComputedVecsFromDateIndex::forced_import( + _4y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "4y_returns", + "4y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _5y_returns: ComputedVecsFromDateIndex::forced_import( + _5y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "5y_returns", + "5y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _6y_returns: ComputedVecsFromDateIndex::forced_import( + _6y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "6y_returns", + "6y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _8y_returns: ComputedVecsFromDateIndex::forced_import( + _8y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "8y_returns", + "8y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - _10y_returns: ComputedVecsFromDateIndex::forced_import( + _10y_price_returns: ComputedVecsFromDateIndex::forced_import( &db, - "10y_returns", + "10y_price_returns", Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -1340,17 +1340,17 @@ impl Vecs { VecBuilderOptions::default().add_last(), )?, - indexes_to_200d_sma_x2_4: ComputedVecsFromDateIndex::forced_import( + indexes_to_price_200d_sma_x2_4: ComputedVecsFromDateIndex::forced_import( &db, - "200d_sma_x2_4", + "price_200d_sma_x2_4", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_200d_sma_x0_8: ComputedVecsFromDateIndex::forced_import( + indexes_to_price_200d_sma_x0_8: ComputedVecsFromDateIndex::forced_import( &db, - "200d_sma_x0_8", + "price_200d_sma_x0_8", Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -1358,7 +1358,16 @@ impl Vecs { )?, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } pub fn compute( @@ -1382,19 +1391,19 @@ impl Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - self.height_to_ath.compute_max( + self.height_to_price_ath.compute_max( starting_indexes.height, - &price.chainindexes_to_high.height, + &price.chainindexes_to_price_high.height, exit, )?; - self.height_to_drawdown.compute_drawdown( + self.height_to_price_drawdown.compute_drawdown( starting_indexes.height, - &price.chainindexes_to_close.height, - &self.height_to_ath, + &price.chainindexes_to_price_close.height, + &self.height_to_price_ath, exit, )?; - self.indexes_to_ath.compute_all( + self.indexes_to_price_ath.compute_all( indexer, indexes, starting_indexes, @@ -1402,14 +1411,14 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_max( starting_indexes.dateindex, - price.timeindexes_to_high.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_high.dateindex.as_ref().unwrap(), exit, )?; Ok(()) }, )?; - self.indexes_to_drawdown.compute_all( + self.indexes_to_price_drawdown.compute_all( indexer, indexes, starting_indexes, @@ -1417,22 +1426,22 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_drawdown( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), - self.indexes_to_ath.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), + self.indexes_to_price_ath.dateindex.as_ref().unwrap(), exit, )?; Ok(()) }, )?; - self.indexes_to_days_since_ath.compute_all( + self.indexes_to_days_since_price_ath.compute_all( indexer, indexes, starting_indexes, exit, |v, _, _, starting_indexes, exit| { let mut high_iter = price - .timeindexes_to_high + .timeindexes_to_price_high .dateindex .as_ref() .unwrap() @@ -1440,7 +1449,7 @@ impl Vecs { let mut prev = None; v.compute_transform( starting_indexes.dateindex, - self.indexes_to_ath.dateindex.as_ref().unwrap(), + self.indexes_to_price_ath.dateindex.as_ref().unwrap(), |(i, ath, slf)| { if prev.is_none() { let i = i.unwrap_to_usize(); @@ -1464,7 +1473,7 @@ impl Vecs { }, )?; - self.indexes_to_max_days_between_aths.compute_all( + self.indexes_to_max_days_between_price_aths.compute_all( indexer, indexes, starting_indexes, @@ -1473,7 +1482,10 @@ impl Vecs { let mut prev = None; v.compute_transform( starting_indexes.dateindex, - self.indexes_to_days_since_ath.dateindex.as_ref().unwrap(), + self.indexes_to_days_since_price_ath + .dateindex + .as_ref() + .unwrap(), |(i, days, slf)| { if prev.is_none() { let i = i.unwrap_to_usize(); @@ -1493,7 +1505,7 @@ impl Vecs { }, )?; - self.indexes_to_max_years_between_aths.compute_all( + self.indexes_to_max_years_between_price_aths.compute_all( indexer, indexes, starting_indexes, @@ -1501,7 +1513,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.indexes_to_max_days_between_aths + self.indexes_to_max_days_between_price_aths .dateindex .as_ref() .unwrap(), @@ -1513,52 +1525,72 @@ impl Vecs { )?; [ - (1, &mut self.price_1d_ago, &mut self._1d_returns, None), - (7, &mut self.price_1w_ago, &mut self._1w_returns, None), - (30, &mut self.price_1m_ago, &mut self._1m_returns, None), - (3 * 30, &mut self.price_3m_ago, &mut self._3m_returns, None), - (6 * 30, &mut self.price_6m_ago, &mut self._6m_returns, None), - (365, &mut self.price_1y_ago, &mut self._1y_returns, None), + (1, &mut self.price_1d_ago, &mut self._1d_price_returns, None), + (7, &mut self.price_1w_ago, &mut self._1w_price_returns, None), + ( + 30, + &mut self.price_1m_ago, + &mut self._1m_price_returns, + None, + ), + ( + 3 * 30, + &mut self.price_3m_ago, + &mut self._3m_price_returns, + None, + ), + ( + 6 * 30, + &mut self.price_6m_ago, + &mut self._6m_price_returns, + None, + ), + ( + 365, + &mut self.price_1y_ago, + &mut self._1y_price_returns, + None, + ), ( 2 * 365, &mut self.price_2y_ago, - &mut self._2y_returns, + &mut self._2y_price_returns, Some(&mut self._2y_cagr), ), ( 3 * 365, &mut self.price_3y_ago, - &mut self._3y_returns, + &mut self._3y_price_returns, Some(&mut self._3y_cagr), ), ( 4 * 365, &mut self.price_4y_ago, - &mut self._4y_returns, + &mut self._4y_price_returns, Some(&mut self._4y_cagr), ), ( 5 * 365, &mut self.price_5y_ago, - &mut self._5y_returns, + &mut self._5y_price_returns, Some(&mut self._5y_cagr), ), ( 6 * 365, &mut self.price_6y_ago, - &mut self._6y_returns, + &mut self._6y_price_returns, Some(&mut self._6y_cagr), ), ( 8 * 365, &mut self.price_8y_ago, - &mut self._8y_returns, + &mut self._8y_price_returns, Some(&mut self._8y_cagr), ), ( 10 * 365, &mut self.price_10y_ago, - &mut self._10y_returns, + &mut self._10y_price_returns, Some(&mut self._10y_cagr), ), ] @@ -1572,7 +1604,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_previous_value( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), days, exit, )?; @@ -1588,7 +1620,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage_change( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), days, exit, )?; @@ -1714,7 +1746,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_dca_stack_via_len( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), days, exit, )?; @@ -1746,7 +1778,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage_difference( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), dca_avg_price.dateindex.as_ref().unwrap(), exit, )?; @@ -1856,7 +1888,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_dca_stack_via_from( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), dateindex, exit, )?; @@ -1888,7 +1920,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage_difference( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), avg_price.dateindex.as_ref().unwrap(), exit, )?; @@ -1901,62 +1933,74 @@ impl Vecs { thread::scope(|s| -> Result<()> { [ - (&mut self.indexes_to_1w_sma, &mut self.indexes_to_1w_ema, 7), - (&mut self.indexes_to_8d_sma, &mut self.indexes_to_8d_ema, 8), ( - &mut self.indexes_to_13d_sma, - &mut self.indexes_to_13d_ema, + &mut self.indexes_to_price_1w_sma, + &mut self.indexes_to_price_1w_ema, + 7, + ), + ( + &mut self.indexes_to_price_8d_sma, + &mut self.indexes_to_price_8d_ema, + 8, + ), + ( + &mut self.indexes_to_price_13d_sma, + &mut self.indexes_to_price_13d_ema, 13, ), ( - &mut self.indexes_to_21d_sma, - &mut self.indexes_to_21d_ema, + &mut self.indexes_to_price_21d_sma, + &mut self.indexes_to_price_21d_ema, 21, ), - (&mut self.indexes_to_1m_sma, &mut self.indexes_to_1m_ema, 30), ( - &mut self.indexes_to_34d_sma, - &mut self.indexes_to_34d_ema, + &mut self.indexes_to_price_1m_sma, + &mut self.indexes_to_price_1m_ema, + 30, + ), + ( + &mut self.indexes_to_price_34d_sma, + &mut self.indexes_to_price_34d_ema, 34, ), ( - &mut self.indexes_to_55d_sma, - &mut self.indexes_to_55d_ema, + &mut self.indexes_to_price_55d_sma, + &mut self.indexes_to_price_55d_ema, 55, ), ( - &mut self.indexes_to_89d_sma, - &mut self.indexes_to_89d_ema, + &mut self.indexes_to_price_89d_sma, + &mut self.indexes_to_price_89d_ema, 89, ), ( - &mut self.indexes_to_144d_sma, - &mut self.indexes_to_144d_ema, + &mut self.indexes_to_price_144d_sma, + &mut self.indexes_to_price_144d_ema, 144, ), ( - &mut self.indexes_to_200d_sma, - &mut self.indexes_to_200d_ema, + &mut self.indexes_to_price_200d_sma, + &mut self.indexes_to_price_200d_ema, 200, ), ( - &mut self.indexes_to_1y_sma, - &mut self.indexes_to_1y_ema, + &mut self.indexes_to_price_1y_sma, + &mut self.indexes_to_price_1y_ema, 365, ), ( - &mut self.indexes_to_2y_sma, - &mut self.indexes_to_2y_ema, + &mut self.indexes_to_price_2y_sma, + &mut self.indexes_to_price_2y_ema, 2 * 365, ), ( - &mut self.indexes_to_200w_sma, - &mut self.indexes_to_200w_ema, + &mut self.indexes_to_price_200w_sma, + &mut self.indexes_to_price_200w_ema, 200 * 7, ), ( - &mut self.indexes_to_4y_sma, - &mut self.indexes_to_4y_ema, + &mut self.indexes_to_price_4y_sma, + &mut self.indexes_to_price_4y_ema, 4 * 365, ), ] @@ -1972,7 +2016,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_sma( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), days, exit, )?; @@ -1989,7 +2033,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_ema( starting_indexes.dateindex, - price.timeindexes_to_close.dateindex.as_ref().unwrap(), + price.timeindexes_to_price_close.dateindex.as_ref().unwrap(), days, exit, )?; @@ -2001,7 +2045,7 @@ impl Vecs { Ok(()) })?; - self.indexes_to_200d_sma_x0_8.compute_all( + self.indexes_to_price_200d_sma_x0_8.compute_all( indexer, indexes, starting_indexes, @@ -2009,7 +2053,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.indexes_to_200d_sma + self.indexes_to_price_200d_sma .price .as_ref() .unwrap() @@ -2023,7 +2067,7 @@ impl Vecs { }, )?; - self.indexes_to_200d_sma_x2_4.compute_all( + self.indexes_to_price_200d_sma_x2_4.compute_all( indexer, indexes, starting_indexes, @@ -2031,7 +2075,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.indexes_to_200d_sma + self.indexes_to_price_200d_sma .price .as_ref() .unwrap() @@ -2050,41 +2094,41 @@ impl Vecs { pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { [ - self.indexes_to_ath.vecs(), - self.indexes_to_drawdown.vecs(), - self.indexes_to_days_since_ath.vecs(), - self.indexes_to_max_days_between_aths.vecs(), - self.indexes_to_max_years_between_aths.vecs(), - self.indexes_to_1w_sma.vecs(), - self.indexes_to_8d_sma.vecs(), - self.indexes_to_13d_sma.vecs(), - self.indexes_to_21d_sma.vecs(), - self.indexes_to_1m_sma.vecs(), - self.indexes_to_34d_sma.vecs(), - self.indexes_to_55d_sma.vecs(), - self.indexes_to_89d_sma.vecs(), - self.indexes_to_144d_sma.vecs(), - self.indexes_to_200d_sma.vecs(), - self.indexes_to_1y_sma.vecs(), - self.indexes_to_2y_sma.vecs(), - self.indexes_to_200w_sma.vecs(), - self.indexes_to_4y_sma.vecs(), - self.indexes_to_1w_ema.vecs(), - self.indexes_to_8d_ema.vecs(), - self.indexes_to_13d_ema.vecs(), - self.indexes_to_21d_ema.vecs(), - self.indexes_to_1m_ema.vecs(), - self.indexes_to_34d_ema.vecs(), - self.indexes_to_55d_ema.vecs(), - self.indexes_to_89d_ema.vecs(), - self.indexes_to_144d_ema.vecs(), - self.indexes_to_200d_ema.vecs(), - self.indexes_to_1y_ema.vecs(), - self.indexes_to_2y_ema.vecs(), - self.indexes_to_200w_ema.vecs(), - self.indexes_to_4y_ema.vecs(), - self.indexes_to_200d_sma_x0_8.vecs(), - self.indexes_to_200d_sma_x2_4.vecs(), + self.indexes_to_price_ath.vecs(), + self.indexes_to_price_drawdown.vecs(), + self.indexes_to_days_since_price_ath.vecs(), + self.indexes_to_max_days_between_price_aths.vecs(), + self.indexes_to_max_years_between_price_aths.vecs(), + self.indexes_to_price_1w_sma.vecs(), + self.indexes_to_price_8d_sma.vecs(), + self.indexes_to_price_13d_sma.vecs(), + self.indexes_to_price_21d_sma.vecs(), + self.indexes_to_price_1m_sma.vecs(), + self.indexes_to_price_34d_sma.vecs(), + self.indexes_to_price_55d_sma.vecs(), + self.indexes_to_price_89d_sma.vecs(), + self.indexes_to_price_144d_sma.vecs(), + self.indexes_to_price_200d_sma.vecs(), + self.indexes_to_price_1y_sma.vecs(), + self.indexes_to_price_2y_sma.vecs(), + self.indexes_to_price_200w_sma.vecs(), + self.indexes_to_price_4y_sma.vecs(), + self.indexes_to_price_1w_ema.vecs(), + self.indexes_to_price_8d_ema.vecs(), + self.indexes_to_price_13d_ema.vecs(), + self.indexes_to_price_21d_ema.vecs(), + self.indexes_to_price_1m_ema.vecs(), + self.indexes_to_price_34d_ema.vecs(), + self.indexes_to_price_55d_ema.vecs(), + self.indexes_to_price_89d_ema.vecs(), + self.indexes_to_price_144d_ema.vecs(), + self.indexes_to_price_200d_ema.vecs(), + self.indexes_to_price_1y_ema.vecs(), + self.indexes_to_price_2y_ema.vecs(), + self.indexes_to_price_200w_ema.vecs(), + self.indexes_to_price_4y_ema.vecs(), + self.indexes_to_price_200d_sma_x0_8.vecs(), + self.indexes_to_price_200d_sma_x2_4.vecs(), self.price_1d_ago.vecs(), self.price_1w_ago.vecs(), self.price_1m_ago.vecs(), @@ -2098,19 +2142,19 @@ impl Vecs { self.price_6y_ago.vecs(), self.price_8y_ago.vecs(), self.price_10y_ago.vecs(), - self._1d_returns.vecs(), - self._1w_returns.vecs(), - self._1m_returns.vecs(), - self._3m_returns.vecs(), - self._6m_returns.vecs(), - self._1y_returns.vecs(), - self._2y_returns.vecs(), - self._3y_returns.vecs(), - self._4y_returns.vecs(), - self._5y_returns.vecs(), - self._6y_returns.vecs(), - self._8y_returns.vecs(), - self._10y_returns.vecs(), + self._1d_price_returns.vecs(), + self._1w_price_returns.vecs(), + self._1m_price_returns.vecs(), + self._3m_price_returns.vecs(), + self._6m_price_returns.vecs(), + self._1y_price_returns.vecs(), + self._2y_price_returns.vecs(), + self._3y_price_returns.vecs(), + self._4y_price_returns.vecs(), + self._5y_price_returns.vecs(), + self._6y_price_returns.vecs(), + self._8y_price_returns.vecs(), + self._10y_price_returns.vecs(), self._2y_cagr.vecs(), self._3y_cagr.vecs(), self._4y_cagr.vecs(), @@ -2194,7 +2238,7 @@ impl Vecs { self.dca_class_2017_returns.vecs(), self.dca_class_2016_returns.vecs(), self.dca_class_2015_returns.vecs(), - vec![&self.height_to_ath, &self.height_to_drawdown], + vec![&self.height_to_price_ath, &self.height_to_price_drawdown], ] .into_iter() .flatten() diff --git a/crates/brk_computer/src/price.rs b/crates/brk_computer/src/price.rs index ce471c49a..54eef63b8 100644 --- a/crates/brk_computer/src/price.rs +++ b/crates/brk_computer/src/price.rs @@ -23,50 +23,50 @@ use super::{ pub struct Vecs { db: Database, - pub dateindex_to_close_in_cents: EagerVec>, - pub dateindex_to_high_in_cents: EagerVec>, - pub dateindex_to_low_in_cents: EagerVec>, - pub dateindex_to_ohlc: RawVec, - pub dateindex_to_ohlc_in_sats: RawVec, - pub dateindex_to_open_in_cents: EagerVec>, - pub height_to_close_in_cents: EagerVec>, - pub height_to_high_in_cents: EagerVec>, - pub height_to_low_in_cents: EagerVec>, - pub height_to_ohlc: RawVec, - pub height_to_ohlc_in_sats: RawVec, - pub height_to_open_in_cents: EagerVec>, - pub timeindexes_to_close: ComputedVecsFromDateIndex>, - pub timeindexes_to_high: ComputedVecsFromDateIndex>, - pub timeindexes_to_low: ComputedVecsFromDateIndex>, - pub timeindexes_to_open: ComputedVecsFromDateIndex>, - pub timeindexes_to_open_in_sats: ComputedVecsFromDateIndex>, - pub timeindexes_to_high_in_sats: ComputedVecsFromDateIndex>, - pub timeindexes_to_low_in_sats: ComputedVecsFromDateIndex>, - pub timeindexes_to_close_in_sats: ComputedVecsFromDateIndex>, - pub chainindexes_to_close: ComputedVecsFromHeightStrict>, - pub chainindexes_to_high: ComputedVecsFromHeightStrict>, - pub chainindexes_to_low: ComputedVecsFromHeightStrict>, - pub chainindexes_to_open: ComputedVecsFromHeightStrict>, - pub chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict>, - pub chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict>, - pub chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict>, - pub chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict>, - pub weekindex_to_ohlc: RawVec, - pub weekindex_to_ohlc_in_sats: RawVec, - pub difficultyepoch_to_ohlc: RawVec, - pub difficultyepoch_to_ohlc_in_sats: RawVec, - pub monthindex_to_ohlc: RawVec, - pub monthindex_to_ohlc_in_sats: RawVec, - pub quarterindex_to_ohlc: RawVec, - pub quarterindex_to_ohlc_in_sats: RawVec, - pub semesterindex_to_ohlc: RawVec, - pub semesterindex_to_ohlc_in_sats: RawVec, - pub yearindex_to_ohlc: RawVec, - pub yearindex_to_ohlc_in_sats: RawVec, - // pub halvingepoch_to_ohlc: StorableVec, - // pub halvingepoch_to_ohlc_in_sats: StorableVec, - pub decadeindex_to_ohlc: RawVec, - pub decadeindex_to_ohlc_in_sats: RawVec, + pub dateindex_to_price_close_in_cents: EagerVec>, + pub dateindex_to_price_high_in_cents: EagerVec>, + pub dateindex_to_price_low_in_cents: EagerVec>, + pub dateindex_to_price_ohlc: RawVec, + pub dateindex_to_price_ohlc_in_sats: RawVec, + pub dateindex_to_price_open_in_cents: EagerVec>, + pub height_to_price_close_in_cents: EagerVec>, + pub height_to_price_high_in_cents: EagerVec>, + pub height_to_price_low_in_cents: EagerVec>, + pub height_to_price_ohlc: RawVec, + pub height_to_price_ohlc_in_sats: RawVec, + pub height_to_price_open_in_cents: EagerVec>, + pub timeindexes_to_price_close: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_high: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_low: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_open: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_open_in_sats: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_high_in_sats: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_low_in_sats: ComputedVecsFromDateIndex>, + pub timeindexes_to_price_close_in_sats: ComputedVecsFromDateIndex>, + pub chainindexes_to_price_close: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_high: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_low: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_open: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_open_in_sats: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_high_in_sats: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_low_in_sats: ComputedVecsFromHeightStrict>, + pub chainindexes_to_price_close_in_sats: ComputedVecsFromHeightStrict>, + pub weekindex_to_price_ohlc: RawVec, + pub weekindex_to_price_ohlc_in_sats: RawVec, + pub difficultyepoch_to_price_ohlc: RawVec, + pub difficultyepoch_to_price_ohlc_in_sats: RawVec, + pub monthindex_to_price_ohlc: RawVec, + pub monthindex_to_price_ohlc_in_sats: RawVec, + pub quarterindex_to_price_ohlc: RawVec, + pub quarterindex_to_price_ohlc_in_sats: RawVec, + pub semesterindex_to_price_ohlc: RawVec, + pub semesterindex_to_price_ohlc_in_sats: RawVec, + pub yearindex_to_price_ohlc: RawVec, + pub yearindex_to_price_ohlc_in_sats: RawVec, + // pub halvingepoch_to_price_ohlc: StorableVec, + // pub halvingepoch_to_price_ohlc_in_sats: StorableVec, + pub decadeindex_to_price_ohlc: RawVec, + pub decadeindex_to_price_ohlc_in_sats: RawVec, } const VERSION: Version = Version::ZERO; @@ -77,250 +77,263 @@ impl Vecs { let db = Database::open(&parent.join("price"))?; db.set_min_len(PAGE_SIZE * 1_000_000)?; - Ok(Self { - dateindex_to_ohlc: RawVec::forced_import( + let this = Self { + dateindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - dateindex_to_ohlc_in_sats: RawVec::forced_import( + dateindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - dateindex_to_close_in_cents: EagerVec::forced_import_compressed( + dateindex_to_price_close_in_cents: EagerVec::forced_import_compressed( &db, - "close_in_cents", + "price_close_in_cents", version + VERSION + Version::ZERO, )?, - dateindex_to_high_in_cents: EagerVec::forced_import_compressed( + dateindex_to_price_high_in_cents: EagerVec::forced_import_compressed( &db, - "high_in_cents", + "price_high_in_cents", version + VERSION + Version::ZERO, )?, - dateindex_to_low_in_cents: EagerVec::forced_import_compressed( + dateindex_to_price_low_in_cents: EagerVec::forced_import_compressed( &db, - "low_in_cents", + "price_low_in_cents", version + VERSION + Version::ZERO, )?, - dateindex_to_open_in_cents: EagerVec::forced_import_compressed( + dateindex_to_price_open_in_cents: EagerVec::forced_import_compressed( &db, - "open_in_cents", + "price_open_in_cents", version + VERSION + Version::ZERO, )?, - height_to_ohlc: RawVec::forced_import(&db, "ohlc", version + VERSION + Version::ZERO)?, - height_to_ohlc_in_sats: RawVec::forced_import( + height_to_price_ohlc: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc", + version + VERSION + Version::ZERO, + )?, + height_to_price_ohlc_in_sats: RawVec::forced_import( + &db, + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - height_to_close_in_cents: EagerVec::forced_import_compressed( + height_to_price_close_in_cents: EagerVec::forced_import_compressed( &db, - "close_in_cents", + "price_close_in_cents", version + VERSION + Version::ZERO, )?, - height_to_high_in_cents: EagerVec::forced_import_compressed( + height_to_price_high_in_cents: EagerVec::forced_import_compressed( &db, - "high_in_cents", + "price_high_in_cents", version + VERSION + Version::ZERO, )?, - height_to_low_in_cents: EagerVec::forced_import_compressed( + height_to_price_low_in_cents: EagerVec::forced_import_compressed( &db, - "low_in_cents", + "price_low_in_cents", version + VERSION + Version::ZERO, )?, - height_to_open_in_cents: EagerVec::forced_import_compressed( + height_to_price_open_in_cents: EagerVec::forced_import_compressed( &db, - "open_in_cents", + "price_open_in_cents", version + VERSION + Version::ZERO, )?, - timeindexes_to_open: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_open: ComputedVecsFromDateIndex::forced_import( &db, - "open", + "price_open", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_first(), )?, - timeindexes_to_high: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_high: ComputedVecsFromDateIndex::forced_import( &db, - "high", + "price_high", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_max(), )?, - timeindexes_to_low: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_low: ComputedVecsFromDateIndex::forced_import( &db, - "low", + "price_low", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_min(), )?, - timeindexes_to_close: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_close: ComputedVecsFromDateIndex::forced_import( &db, - "close", + "price_close", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_open_in_sats: ComputedVecsFromDateIndex::forced_import( &db, - "open_in_sats", + "price_open_in_sats", Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, indexes, VecBuilderOptions::default().add_first(), )?, - timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_high_in_sats: ComputedVecsFromDateIndex::forced_import( &db, - "high_in_sats", + "price_high_in_sats", Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, indexes, VecBuilderOptions::default().add_max(), )?, - timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_low_in_sats: ComputedVecsFromDateIndex::forced_import( &db, - "low_in_sats", + "price_low_in_sats", Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, indexes, VecBuilderOptions::default().add_min(), )?, - timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import( + timeindexes_to_price_close_in_sats: ComputedVecsFromDateIndex::forced_import( &db, - "close_in_sats", + "price_close_in_sats", Source::Compute, version + VERSION + VERSION_IN_SATS + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_open: ComputedVecsFromHeightStrict::forced_import( &db, - "open", + "price_open", version + VERSION + Version::ZERO, VecBuilderOptions::default().add_first(), )?, - chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_high: ComputedVecsFromHeightStrict::forced_import( &db, - "high", + "price_high", version + VERSION + Version::ZERO, VecBuilderOptions::default().add_max(), )?, - chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_low: ComputedVecsFromHeightStrict::forced_import( &db, - "low", + "price_low", version + VERSION + Version::ZERO, VecBuilderOptions::default().add_min(), )?, - chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_close: ComputedVecsFromHeightStrict::forced_import( &db, - "close", + "price_close", version + VERSION + Version::ZERO, VecBuilderOptions::default().add_last(), )?, - chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_open_in_sats: ComputedVecsFromHeightStrict::forced_import( &db, - "open_in_sats", + "price_open_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, VecBuilderOptions::default().add_first(), )?, - chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_high_in_sats: ComputedVecsFromHeightStrict::forced_import( &db, - "high_in_sats", + "price_high_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, VecBuilderOptions::default().add_max(), )?, - chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_low_in_sats: ComputedVecsFromHeightStrict::forced_import( &db, - "low_in_sats", + "price_low_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, VecBuilderOptions::default().add_min(), )?, - chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import( + chainindexes_to_price_close_in_sats: ComputedVecsFromHeightStrict::forced_import( &db, - "close_in_sats", + "price_close_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, VecBuilderOptions::default().add_last(), )?, - weekindex_to_ohlc: RawVec::forced_import( + weekindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - weekindex_to_ohlc_in_sats: RawVec::forced_import( + weekindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - difficultyepoch_to_ohlc: RawVec::forced_import( + difficultyepoch_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - difficultyepoch_to_ohlc_in_sats: RawVec::forced_import( + difficultyepoch_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - monthindex_to_ohlc: RawVec::forced_import( + monthindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - monthindex_to_ohlc_in_sats: RawVec::forced_import( + monthindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - quarterindex_to_ohlc: RawVec::forced_import( + quarterindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - quarterindex_to_ohlc_in_sats: RawVec::forced_import( + quarterindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - semesterindex_to_ohlc: RawVec::forced_import( + semesterindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - semesterindex_to_ohlc_in_sats: RawVec::forced_import( + semesterindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - yearindex_to_ohlc: RawVec::forced_import( + yearindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - yearindex_to_ohlc_in_sats: RawVec::forced_import( + yearindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, - // halvingepoch_to_ohlc: StorableVec::forced_import(db, - // "halvingepoch_to_ohlc"), version + VERSION + Version::ZERO, format)?, - decadeindex_to_ohlc: RawVec::forced_import( + // halvingepoch_to_price_ohlc: StorableVec::forced_import(db, + // "halvingepoch_to_price_ohlc"), version + VERSION + Version::ZERO, format)?, + decadeindex_to_price_ohlc: RawVec::forced_import( &db, - "ohlc", + "price_ohlc", version + VERSION + Version::ZERO, )?, - decadeindex_to_ohlc_in_sats: RawVec::forced_import( + decadeindex_to_price_ohlc_in_sats: RawVec::forced_import( &db, - "ohlc_in_sats", + "price_ohlc_in_sats", version + VERSION + VERSION_IN_SATS + Version::ZERO, )?, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } pub fn compute( @@ -344,92 +357,95 @@ impl Vecs { fetched: &fetched::Vecs, exit: &Exit, ) -> Result<()> { - self.height_to_open_in_cents.compute_transform( + self.height_to_price_open_in_cents.compute_transform( starting_indexes.height, - &fetched.height_to_ohlc_in_cents, + &fetched.height_to_price_ohlc_in_cents, |(di, ohlc, ..)| (di, ohlc.open), exit, )?; - self.height_to_high_in_cents.compute_transform( + self.height_to_price_high_in_cents.compute_transform( starting_indexes.height, - &fetched.height_to_ohlc_in_cents, + &fetched.height_to_price_ohlc_in_cents, |(di, ohlc, ..)| (di, ohlc.high), exit, )?; - self.height_to_low_in_cents.compute_transform( + self.height_to_price_low_in_cents.compute_transform( starting_indexes.height, - &fetched.height_to_ohlc_in_cents, + &fetched.height_to_price_ohlc_in_cents, |(di, ohlc, ..)| (di, ohlc.low), exit, )?; - self.height_to_close_in_cents.compute_transform( + self.height_to_price_close_in_cents.compute_transform( starting_indexes.height, - &fetched.height_to_ohlc_in_cents, + &fetched.height_to_price_ohlc_in_cents, |(di, ohlc, ..)| (di, ohlc.close), exit, )?; let index = starting_indexes .height - .min(Height::from(self.height_to_ohlc.len())); + .min(Height::from(self.height_to_price_ohlc.len())); fetched - .height_to_ohlc_in_cents + .height_to_price_ohlc_in_cents .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { - self.height_to_ohlc - .forced_push_at(i, OHLCDollars::from(v.into_owned()), exit)?; - Ok(()) - })?; - self.height_to_ohlc.safe_flush(exit)?; - - self.dateindex_to_open_in_cents.compute_transform( - starting_indexes.dateindex, - &fetched.dateindex_to_ohlc_in_cents, - |(di, ohlc, ..)| (di, ohlc.open), - exit, - )?; - - self.dateindex_to_high_in_cents.compute_transform( - starting_indexes.dateindex, - &fetched.dateindex_to_ohlc_in_cents, - |(di, ohlc, ..)| (di, ohlc.high), - exit, - )?; - - self.dateindex_to_low_in_cents.compute_transform( - starting_indexes.dateindex, - &fetched.dateindex_to_ohlc_in_cents, - |(di, ohlc, ..)| (di, ohlc.low), - exit, - )?; - - self.dateindex_to_close_in_cents.compute_transform( - starting_indexes.dateindex, - &fetched.dateindex_to_ohlc_in_cents, - |(di, ohlc, ..)| (di, ohlc.close), - exit, - )?; - - let index = starting_indexes - .dateindex - .min(DateIndex::from(self.dateindex_to_ohlc.len())); - fetched - .dateindex_to_ohlc_in_cents - .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - self.dateindex_to_ohlc.forced_push_at( + self.height_to_price_ohlc.forced_push_at( i, OHLCDollars::from(v.into_owned()), exit, )?; Ok(()) })?; - self.dateindex_to_ohlc.safe_flush(exit)?; + self.height_to_price_ohlc.safe_flush(exit)?; - self.timeindexes_to_close.compute_all( + self.dateindex_to_price_open_in_cents.compute_transform( + starting_indexes.dateindex, + &fetched.dateindex_to_price_ohlc_in_cents, + |(di, ohlc, ..)| (di, ohlc.open), + exit, + )?; + + self.dateindex_to_price_high_in_cents.compute_transform( + starting_indexes.dateindex, + &fetched.dateindex_to_price_ohlc_in_cents, + |(di, ohlc, ..)| (di, ohlc.high), + exit, + )?; + + self.dateindex_to_price_low_in_cents.compute_transform( + starting_indexes.dateindex, + &fetched.dateindex_to_price_ohlc_in_cents, + |(di, ohlc, ..)| (di, ohlc.low), + exit, + )?; + + self.dateindex_to_price_close_in_cents.compute_transform( + starting_indexes.dateindex, + &fetched.dateindex_to_price_ohlc_in_cents, + |(di, ohlc, ..)| (di, ohlc.close), + exit, + )?; + + let index = starting_indexes + .dateindex + .min(DateIndex::from(self.dateindex_to_price_ohlc.len())); + fetched + .dateindex_to_price_ohlc_in_cents + .iter_at(index) + .try_for_each(|(i, v)| -> Result<()> { + self.dateindex_to_price_ohlc.forced_push_at( + i, + OHLCDollars::from(v.into_owned()), + exit, + )?; + Ok(()) + })?; + self.dateindex_to_price_ohlc.safe_flush(exit)?; + + self.timeindexes_to_price_close.compute_all( indexer, indexes, starting_indexes, @@ -437,7 +453,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - &self.dateindex_to_ohlc, + &self.dateindex_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.close), exit, )?; @@ -445,7 +461,7 @@ impl Vecs { }, )?; - self.timeindexes_to_high.compute_all( + self.timeindexes_to_price_high.compute_all( indexer, indexes, starting_indexes, @@ -453,7 +469,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - &self.dateindex_to_ohlc, + &self.dateindex_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.high), exit, )?; @@ -461,7 +477,7 @@ impl Vecs { }, )?; - self.timeindexes_to_low.compute_all( + self.timeindexes_to_price_low.compute_all( indexer, indexes, starting_indexes, @@ -469,7 +485,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - &self.dateindex_to_ohlc, + &self.dateindex_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.low), exit, )?; @@ -477,7 +493,7 @@ impl Vecs { }, )?; - self.timeindexes_to_open.compute_all( + self.timeindexes_to_price_open.compute_all( indexer, indexes, starting_indexes, @@ -485,7 +501,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - &self.dateindex_to_ohlc, + &self.dateindex_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.open), exit, )?; @@ -493,7 +509,7 @@ impl Vecs { }, )?; - self.chainindexes_to_close.compute( + self.chainindexes_to_price_close.compute( indexer, indexes, starting_indexes, @@ -501,7 +517,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.height_to_ohlc, + &self.height_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.close), exit, )?; @@ -509,7 +525,7 @@ impl Vecs { }, )?; - self.chainindexes_to_high.compute( + self.chainindexes_to_price_high.compute( indexer, indexes, starting_indexes, @@ -517,7 +533,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.height_to_ohlc, + &self.height_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.high), exit, )?; @@ -525,7 +541,7 @@ impl Vecs { }, )?; - self.chainindexes_to_low.compute( + self.chainindexes_to_price_low.compute( indexer, indexes, starting_indexes, @@ -533,7 +549,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.height_to_ohlc, + &self.height_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.low), exit, )?; @@ -541,7 +557,7 @@ impl Vecs { }, )?; - self.chainindexes_to_open.compute( + self.chainindexes_to_price_open.compute( indexer, indexes, starting_indexes, @@ -549,7 +565,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.height_to_ohlc, + &self.height_to_price_ohlc, |(di, ohlc, ..)| (di, ohlc.open), exit, )?; @@ -557,13 +573,17 @@ impl Vecs { }, )?; - let mut weekindex_first_iter = self.timeindexes_to_open.weekindex.unwrap_first().iter(); - let mut weekindex_max_iter = self.timeindexes_to_high.weekindex.unwrap_max().iter(); - let mut weekindex_min_iter = self.timeindexes_to_low.weekindex.unwrap_min().iter(); + let mut weekindex_first_iter = self + .timeindexes_to_price_open + .weekindex + .unwrap_first() + .iter(); + let mut weekindex_max_iter = self.timeindexes_to_price_high.weekindex.unwrap_max().iter(); + let mut weekindex_min_iter = self.timeindexes_to_price_low.weekindex.unwrap_min().iter(); let index = starting_indexes .weekindex - .min(WeekIndex::from(self.weekindex_to_ohlc.len())); - self.timeindexes_to_close + .min(WeekIndex::from(self.weekindex_to_price_ohlc.len())); + self.timeindexes_to_price_close .weekindex .unwrap_last() .iter_at(index) @@ -572,7 +592,7 @@ impl Vecs { 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); - self.weekindex_to_ohlc.forced_push_at( + self.weekindex_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -584,24 +604,27 @@ impl Vecs { )?; Ok(()) })?; - self.weekindex_to_ohlc.safe_flush(exit)?; + self.weekindex_to_price_ohlc.safe_flush(exit)?; let mut difficultyepoch_first_iter = self - .chainindexes_to_open + .chainindexes_to_price_open .difficultyepoch .unwrap_first() .iter(); let mut difficultyepoch_max_iter = self - .chainindexes_to_high + .chainindexes_to_price_high .difficultyepoch .unwrap_max() .iter(); - let mut difficultyepoch_min_iter = - self.chainindexes_to_low.difficultyepoch.unwrap_min().iter(); - let index = starting_indexes + let mut difficultyepoch_min_iter = self + .chainindexes_to_price_low .difficultyepoch - .min(DifficultyEpoch::from(self.difficultyepoch_to_ohlc.len())); - self.chainindexes_to_close + .unwrap_min() + .iter(); + let index = starting_indexes.difficultyepoch.min(DifficultyEpoch::from( + self.difficultyepoch_to_price_ohlc.len(), + )); + self.chainindexes_to_price_close .difficultyepoch .unwrap_last() .iter_at(index) @@ -610,7 +633,7 @@ impl Vecs { let open = difficultyepoch_first_iter.unwrap_get_inner(i); let high = difficultyepoch_max_iter.unwrap_get_inner(i); let low = difficultyepoch_min_iter.unwrap_get_inner(i); - self.difficultyepoch_to_ohlc.forced_push_at( + self.difficultyepoch_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -622,15 +645,23 @@ impl Vecs { )?; Ok(()) })?; - self.difficultyepoch_to_ohlc.safe_flush(exit)?; + self.difficultyepoch_to_price_ohlc.safe_flush(exit)?; - let mut monthindex_first_iter = self.timeindexes_to_open.monthindex.unwrap_first().iter(); - let mut monthindex_max_iter = self.timeindexes_to_high.monthindex.unwrap_max().iter(); - let mut monthindex_min_iter = self.timeindexes_to_low.monthindex.unwrap_min().iter(); + let mut monthindex_first_iter = self + .timeindexes_to_price_open + .monthindex + .unwrap_first() + .iter(); + let mut monthindex_max_iter = self + .timeindexes_to_price_high + .monthindex + .unwrap_max() + .iter(); + let mut monthindex_min_iter = self.timeindexes_to_price_low.monthindex.unwrap_min().iter(); let index = starting_indexes .monthindex - .min(MonthIndex::from(self.monthindex_to_ohlc.len())); - self.timeindexes_to_close + .min(MonthIndex::from(self.monthindex_to_price_ohlc.len())); + self.timeindexes_to_price_close .monthindex .unwrap_last() .iter_at(index) @@ -639,7 +670,7 @@ impl Vecs { let open = monthindex_first_iter.unwrap_get_inner(i); let high = monthindex_max_iter.unwrap_get_inner(i); let low = monthindex_min_iter.unwrap_get_inner(i); - self.monthindex_to_ohlc.forced_push_at( + self.monthindex_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -651,16 +682,27 @@ impl Vecs { )?; Ok(()) })?; - self.monthindex_to_ohlc.safe_flush(exit)?; + self.monthindex_to_price_ohlc.safe_flush(exit)?; - let mut quarterindex_first_iter = - self.timeindexes_to_open.quarterindex.unwrap_first().iter(); - let mut quarterindex_max_iter = self.timeindexes_to_high.quarterindex.unwrap_max().iter(); - let mut quarterindex_min_iter = self.timeindexes_to_low.quarterindex.unwrap_min().iter(); + let mut quarterindex_first_iter = self + .timeindexes_to_price_open + .quarterindex + .unwrap_first() + .iter(); + let mut quarterindex_max_iter = self + .timeindexes_to_price_high + .quarterindex + .unwrap_max() + .iter(); + let mut quarterindex_min_iter = self + .timeindexes_to_price_low + .quarterindex + .unwrap_min() + .iter(); let index = starting_indexes .quarterindex - .min(QuarterIndex::from(self.quarterindex_to_ohlc.len())); - self.timeindexes_to_close + .min(QuarterIndex::from(self.quarterindex_to_price_ohlc.len())); + self.timeindexes_to_price_close .quarterindex .unwrap_last() .iter_at(index) @@ -669,7 +711,7 @@ impl Vecs { let open = quarterindex_first_iter.unwrap_get_inner(i); let high = quarterindex_max_iter.unwrap_get_inner(i); let low = quarterindex_min_iter.unwrap_get_inner(i); - self.quarterindex_to_ohlc.forced_push_at( + self.quarterindex_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -681,16 +723,27 @@ impl Vecs { )?; Ok(()) })?; - self.quarterindex_to_ohlc.safe_flush(exit)?; + self.quarterindex_to_price_ohlc.safe_flush(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(); + let mut semesterindex_first_iter = self + .timeindexes_to_price_open + .semesterindex + .unwrap_first() + .iter(); + let mut semesterindex_max_iter = self + .timeindexes_to_price_high + .semesterindex + .unwrap_max() + .iter(); + let mut semesterindex_min_iter = self + .timeindexes_to_price_low + .semesterindex + .unwrap_min() + .iter(); let index = starting_indexes .semesterindex - .min(SemesterIndex::from(self.semesterindex_to_ohlc.len())); - self.timeindexes_to_close + .min(SemesterIndex::from(self.semesterindex_to_price_ohlc.len())); + self.timeindexes_to_price_close .semesterindex .unwrap_last() .iter_at(index) @@ -699,7 +752,7 @@ impl Vecs { let open = semesterindex_first_iter.unwrap_get_inner(i); let high = semesterindex_max_iter.unwrap_get_inner(i); let low = semesterindex_min_iter.unwrap_get_inner(i); - self.semesterindex_to_ohlc.forced_push_at( + self.semesterindex_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -711,15 +764,19 @@ impl Vecs { )?; Ok(()) })?; - self.semesterindex_to_ohlc.safe_flush(exit)?; + self.semesterindex_to_price_ohlc.safe_flush(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(); + let mut yearindex_first_iter = self + .timeindexes_to_price_open + .yearindex + .unwrap_first() + .iter(); + let mut yearindex_max_iter = self.timeindexes_to_price_high.yearindex.unwrap_max().iter(); + let mut yearindex_min_iter = self.timeindexes_to_price_low.yearindex.unwrap_min().iter(); let index = starting_indexes .yearindex - .min(YearIndex::from(self.yearindex_to_ohlc.len())); - self.timeindexes_to_close + .min(YearIndex::from(self.yearindex_to_price_ohlc.len())); + self.timeindexes_to_price_close .yearindex .unwrap_last() .iter_at(index) @@ -728,7 +785,7 @@ impl Vecs { let open = yearindex_first_iter.unwrap_get_inner(i); let high = yearindex_max_iter.unwrap_get_inner(i); let low = yearindex_min_iter.unwrap_get_inner(i); - self.yearindex_to_ohlc.forced_push_at( + self.yearindex_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -740,18 +797,30 @@ impl Vecs { )?; Ok(()) })?; - self.yearindex_to_ohlc.safe_flush(exit)?; + self.yearindex_to_price_ohlc.safe_flush(exit)?; - // self.halvingepoch_to_ohlc + // self.halvingepoch_to_price_ohlc // .compute_transform(starting_indexes.halvingepoch, other, t, exit)?; - let mut decadeindex_first_iter = self.timeindexes_to_open.decadeindex.unwrap_first().iter(); - let mut decadeindex_max_iter = self.timeindexes_to_high.decadeindex.unwrap_max().iter(); - let mut decadeindex_min_iter = self.timeindexes_to_low.decadeindex.unwrap_min().iter(); + let mut decadeindex_first_iter = self + .timeindexes_to_price_open + .decadeindex + .unwrap_first() + .iter(); + let mut decadeindex_max_iter = self + .timeindexes_to_price_high + .decadeindex + .unwrap_max() + .iter(); + let mut decadeindex_min_iter = self + .timeindexes_to_price_low + .decadeindex + .unwrap_min() + .iter(); let index = starting_indexes .decadeindex - .min(DecadeIndex::from(self.decadeindex_to_ohlc.len())); - self.timeindexes_to_close + .min(DecadeIndex::from(self.decadeindex_to_price_ohlc.len())); + self.timeindexes_to_price_close .decadeindex .unwrap_last() .iter_at(index) @@ -760,7 +829,7 @@ impl Vecs { let open = decadeindex_first_iter.unwrap_get_inner(i); let high = decadeindex_max_iter.unwrap_get_inner(i); let low = decadeindex_min_iter.unwrap_get_inner(i); - self.decadeindex_to_ohlc.forced_push_at( + self.decadeindex_to_price_ohlc.forced_push_at( i, OHLCDollars { open, @@ -772,9 +841,9 @@ impl Vecs { )?; Ok(()) })?; - self.decadeindex_to_ohlc.safe_flush(exit)?; + self.decadeindex_to_price_ohlc.safe_flush(exit)?; - self.chainindexes_to_open_in_sats.compute( + self.chainindexes_to_price_open_in_sats.compute( indexer, indexes, starting_indexes, @@ -782,7 +851,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.chainindexes_to_open.height, + &self.chainindexes_to_price_open.height, |(i, open, ..)| (i, Open::new(Sats::ONE_BTC / *open)), exit, )?; @@ -790,7 +859,7 @@ impl Vecs { }, )?; - self.chainindexes_to_high_in_sats.compute( + self.chainindexes_to_price_high_in_sats.compute( indexer, indexes, starting_indexes, @@ -798,7 +867,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.chainindexes_to_low.height, + &self.chainindexes_to_price_low.height, |(i, low, ..)| (i, High::new(Sats::ONE_BTC / *low)), exit, )?; @@ -806,7 +875,7 @@ impl Vecs { }, )?; - self.chainindexes_to_low_in_sats.compute( + self.chainindexes_to_price_low_in_sats.compute( indexer, indexes, starting_indexes, @@ -814,7 +883,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.chainindexes_to_high.height, + &self.chainindexes_to_price_high.height, |(i, high, ..)| (i, Low::new(Sats::ONE_BTC / *high)), exit, )?; @@ -822,7 +891,7 @@ impl Vecs { }, )?; - self.chainindexes_to_close_in_sats.compute( + self.chainindexes_to_price_close_in_sats.compute( indexer, indexes, starting_indexes, @@ -830,7 +899,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.height, - &self.chainindexes_to_close.height, + &self.chainindexes_to_price_close.height, |(i, close, ..)| (i, Close::new(Sats::ONE_BTC / *close)), exit, )?; @@ -838,7 +907,7 @@ impl Vecs { }, )?; - self.timeindexes_to_open_in_sats.compute_all( + self.timeindexes_to_price_open_in_sats.compute_all( indexer, indexes, starting_indexes, @@ -846,7 +915,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.timeindexes_to_open.dateindex.as_ref().unwrap(), + self.timeindexes_to_price_open.dateindex.as_ref().unwrap(), |(i, open, ..)| (i, Open::new(Sats::ONE_BTC / *open)), exit, )?; @@ -854,7 +923,7 @@ impl Vecs { }, )?; - self.timeindexes_to_high_in_sats.compute_all( + self.timeindexes_to_price_high_in_sats.compute_all( indexer, indexes, starting_indexes, @@ -862,7 +931,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.timeindexes_to_low.dateindex.as_ref().unwrap(), + self.timeindexes_to_price_low.dateindex.as_ref().unwrap(), |(i, low, ..)| (i, High::new(Sats::ONE_BTC / *low)), exit, )?; @@ -870,7 +939,7 @@ impl Vecs { }, )?; - self.timeindexes_to_low_in_sats.compute_all( + self.timeindexes_to_price_low_in_sats.compute_all( indexer, indexes, starting_indexes, @@ -878,7 +947,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.timeindexes_to_high.dateindex.as_ref().unwrap(), + self.timeindexes_to_price_high.dateindex.as_ref().unwrap(), |(i, high, ..)| (i, Low::new(Sats::ONE_BTC / *high)), exit, )?; @@ -886,7 +955,7 @@ impl Vecs { }, )?; - self.timeindexes_to_close_in_sats.compute_all( + self.timeindexes_to_price_close_in_sats.compute_all( indexer, indexes, starting_indexes, @@ -894,7 +963,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_transform( starting_indexes.dateindex, - self.timeindexes_to_close.dateindex.as_ref().unwrap(), + self.timeindexes_to_price_close.dateindex.as_ref().unwrap(), |(i, close, ..)| (i, Close::new(Sats::ONE_BTC / *close)), exit, )?; @@ -902,18 +971,18 @@ impl Vecs { }, )?; - let mut height_first_iter = self.chainindexes_to_open_in_sats.height.iter(); - let mut height_max_iter = self.chainindexes_to_high_in_sats.height.iter(); - let mut height_min_iter = self.chainindexes_to_low_in_sats.height.iter(); + let mut height_first_iter = self.chainindexes_to_price_open_in_sats.height.iter(); + let mut height_max_iter = self.chainindexes_to_price_high_in_sats.height.iter(); + let mut height_min_iter = self.chainindexes_to_price_low_in_sats.height.iter(); let index = starting_indexes .height - .min(Height::from(self.height_to_ohlc_in_sats.len())); - self.chainindexes_to_close_in_sats + .min(Height::from(self.height_to_price_ohlc_in_sats.len())); + self.chainindexes_to_price_close_in_sats .height .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.height_to_ohlc_in_sats.forced_push_at( + self.height_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: height_first_iter.unwrap_get_inner(i), @@ -925,37 +994,37 @@ impl Vecs { )?; Ok(()) })?; - self.height_to_ohlc_in_sats.safe_flush(exit)?; + self.height_to_price_ohlc_in_sats.safe_flush(exit)?; let mut dateindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .dateindex .as_ref() .unwrap() .iter(); let mut dateindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .dateindex .as_ref() .unwrap() .iter(); let mut dateindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .dateindex .as_ref() .unwrap() .iter(); let index = starting_indexes .dateindex - .min(DateIndex::from(self.dateindex_to_ohlc_in_sats.len())); - self.timeindexes_to_close_in_sats + .min(DateIndex::from(self.dateindex_to_price_ohlc_in_sats.len())); + self.timeindexes_to_price_close_in_sats .dateindex .as_ref() .unwrap() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.dateindex_to_ohlc_in_sats.forced_push_at( + self.dateindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: dateindex_first_iter.unwrap_get_inner(i), @@ -967,33 +1036,33 @@ impl Vecs { )?; Ok(()) })?; - self.dateindex_to_ohlc_in_sats.safe_flush(exit)?; + self.dateindex_to_price_ohlc_in_sats.safe_flush(exit)?; let mut weekindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .weekindex .unwrap_first() .iter(); let mut weekindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .weekindex .unwrap_max() .iter(); let mut weekindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .weekindex .unwrap_min() .iter(); let index = starting_indexes .weekindex - .min(WeekIndex::from(self.weekindex_to_ohlc_in_sats.len())); - self.timeindexes_to_close_in_sats + .min(WeekIndex::from(self.weekindex_to_price_ohlc_in_sats.len())); + self.timeindexes_to_price_close_in_sats .weekindex .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.weekindex_to_ohlc_in_sats.forced_push_at( + self.weekindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: weekindex_first_iter.unwrap_get_inner(i), @@ -1005,33 +1074,33 @@ impl Vecs { )?; Ok(()) })?; - self.weekindex_to_ohlc_in_sats.safe_flush(exit)?; + self.weekindex_to_price_ohlc_in_sats.safe_flush(exit)?; let mut difficultyepoch_first_iter = self - .chainindexes_to_open_in_sats + .chainindexes_to_price_open_in_sats .difficultyepoch .unwrap_first() .iter(); let mut difficultyepoch_max_iter = self - .chainindexes_to_high_in_sats + .chainindexes_to_price_high_in_sats .difficultyepoch .unwrap_max() .iter(); let mut difficultyepoch_min_iter = self - .chainindexes_to_low_in_sats + .chainindexes_to_price_low_in_sats .difficultyepoch .unwrap_min() .iter(); let index = starting_indexes.difficultyepoch.min(DifficultyEpoch::from( - self.difficultyepoch_to_ohlc_in_sats.len(), + self.difficultyepoch_to_price_ohlc_in_sats.len(), )); - self.chainindexes_to_close_in_sats + self.chainindexes_to_price_close_in_sats .difficultyepoch .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.difficultyepoch_to_ohlc_in_sats.forced_push_at( + self.difficultyepoch_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: difficultyepoch_first_iter.unwrap_get_inner(i), @@ -1043,33 +1112,34 @@ impl Vecs { )?; Ok(()) })?; - self.difficultyepoch_to_ohlc_in_sats.safe_flush(exit)?; + self.difficultyepoch_to_price_ohlc_in_sats + .safe_flush(exit)?; let mut monthindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .monthindex .unwrap_first() .iter(); let mut monthindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .monthindex .unwrap_max() .iter(); let mut monthindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .monthindex .unwrap_min() .iter(); - let index = starting_indexes - .monthindex - .min(MonthIndex::from(self.monthindex_to_ohlc_in_sats.len())); - self.timeindexes_to_close_in_sats + let index = starting_indexes.monthindex.min(MonthIndex::from( + self.monthindex_to_price_ohlc_in_sats.len(), + )); + self.timeindexes_to_price_close_in_sats .monthindex .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.monthindex_to_ohlc_in_sats.forced_push_at( + self.monthindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: monthindex_first_iter.unwrap_get_inner(i), @@ -1081,33 +1151,33 @@ impl Vecs { )?; Ok(()) })?; - self.monthindex_to_ohlc_in_sats.safe_flush(exit)?; + self.monthindex_to_price_ohlc_in_sats.safe_flush(exit)?; let mut quarterindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .quarterindex .unwrap_first() .iter(); let mut quarterindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .quarterindex .unwrap_max() .iter(); let mut quarterindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .quarterindex .unwrap_min() .iter(); - let index = starting_indexes - .quarterindex - .min(QuarterIndex::from(self.quarterindex_to_ohlc_in_sats.len())); - self.timeindexes_to_close_in_sats + let index = starting_indexes.quarterindex.min(QuarterIndex::from( + self.quarterindex_to_price_ohlc_in_sats.len(), + )); + self.timeindexes_to_price_close_in_sats .quarterindex .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.quarterindex_to_ohlc_in_sats.forced_push_at( + self.quarterindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: quarterindex_first_iter.unwrap_get_inner(i), @@ -1119,33 +1189,33 @@ impl Vecs { )?; Ok(()) })?; - self.quarterindex_to_ohlc_in_sats.safe_flush(exit)?; + self.quarterindex_to_price_ohlc_in_sats.safe_flush(exit)?; let mut semesterindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .semesterindex .unwrap_first() .iter(); let mut semesterindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .semesterindex .unwrap_max() .iter(); let mut semesterindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .semesterindex .unwrap_min() .iter(); let index = starting_indexes.semesterindex.min(SemesterIndex::from( - self.semesterindex_to_ohlc_in_sats.len(), + self.semesterindex_to_price_ohlc_in_sats.len(), )); - self.timeindexes_to_close_in_sats + self.timeindexes_to_price_close_in_sats .semesterindex .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.semesterindex_to_ohlc_in_sats.forced_push_at( + self.semesterindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: semesterindex_first_iter.unwrap_get_inner(i), @@ -1157,33 +1227,33 @@ impl Vecs { )?; Ok(()) })?; - self.semesterindex_to_ohlc_in_sats.safe_flush(exit)?; + self.semesterindex_to_price_ohlc_in_sats.safe_flush(exit)?; let mut yearindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .yearindex .unwrap_first() .iter(); let mut yearindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .yearindex .unwrap_max() .iter(); let mut yearindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .yearindex .unwrap_min() .iter(); let index = starting_indexes .yearindex - .min(YearIndex::from(self.yearindex_to_ohlc_in_sats.len())); - self.timeindexes_to_close_in_sats + .min(YearIndex::from(self.yearindex_to_price_ohlc_in_sats.len())); + self.timeindexes_to_price_close_in_sats .yearindex .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.yearindex_to_ohlc_in_sats.forced_push_at( + self.yearindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: yearindex_first_iter.unwrap_get_inner(i), @@ -1195,36 +1265,36 @@ impl Vecs { )?; Ok(()) })?; - self.yearindex_to_ohlc_in_sats.safe_flush(exit)?; + self.yearindex_to_price_ohlc_in_sats.safe_flush(exit)?; - // self.halvingepoch_to_ohlc + // self.halvingepoch_to_price_ohlc // _in_sats.compute_transform(starting_indexes.halvingepoch, other, t, exit)?; let mut decadeindex_first_iter = self - .timeindexes_to_open_in_sats + .timeindexes_to_price_open_in_sats .decadeindex .unwrap_first() .iter(); let mut decadeindex_max_iter = self - .timeindexes_to_high_in_sats + .timeindexes_to_price_high_in_sats .decadeindex .unwrap_max() .iter(); let mut decadeindex_min_iter = self - .timeindexes_to_low_in_sats + .timeindexes_to_price_low_in_sats .decadeindex .unwrap_min() .iter(); - let index = starting_indexes - .decadeindex - .min(DecadeIndex::from(self.decadeindex_to_ohlc_in_sats.len())); - self.timeindexes_to_close_in_sats + let index = starting_indexes.decadeindex.min(DecadeIndex::from( + self.decadeindex_to_price_ohlc_in_sats.len(), + )); + self.timeindexes_to_price_close_in_sats .decadeindex .unwrap_last() .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { let close = v.into_owned(); - self.decadeindex_to_ohlc_in_sats.forced_push_at( + self.decadeindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { open: decadeindex_first_iter.unwrap_get_inner(i), @@ -1236,7 +1306,7 @@ impl Vecs { )?; Ok(()) })?; - self.decadeindex_to_ohlc_in_sats.safe_flush(exit)?; + self.decadeindex_to_price_ohlc_in_sats.safe_flush(exit)?; Ok(()) } @@ -1244,51 +1314,51 @@ impl Vecs { pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { vec![ vec![ - &self.dateindex_to_close_in_cents as &dyn AnyCollectableVec, - &self.dateindex_to_high_in_cents, - &self.dateindex_to_low_in_cents, - &self.dateindex_to_ohlc, - &self.dateindex_to_open_in_cents, - &self.height_to_close_in_cents, - &self.height_to_high_in_cents, - &self.height_to_low_in_cents, - &self.height_to_ohlc, - &self.height_to_open_in_cents, - &self.weekindex_to_ohlc, - &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, - &self.height_to_ohlc_in_sats, - &self.dateindex_to_ohlc_in_sats, - &self.weekindex_to_ohlc_in_sats, - &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, + &self.dateindex_to_price_close_in_cents as &dyn AnyCollectableVec, + &self.dateindex_to_price_high_in_cents, + &self.dateindex_to_price_low_in_cents, + &self.dateindex_to_price_ohlc, + &self.dateindex_to_price_open_in_cents, + &self.height_to_price_close_in_cents, + &self.height_to_price_high_in_cents, + &self.height_to_price_low_in_cents, + &self.height_to_price_ohlc, + &self.height_to_price_open_in_cents, + &self.weekindex_to_price_ohlc, + &self.difficultyepoch_to_price_ohlc, + &self.monthindex_to_price_ohlc, + &self.quarterindex_to_price_ohlc, + &self.semesterindex_to_price_ohlc, + &self.yearindex_to_price_ohlc, + // &self.halvingepoch_to_price_ohlc, + &self.decadeindex_to_price_ohlc, + &self.height_to_price_ohlc_in_sats, + &self.dateindex_to_price_ohlc_in_sats, + &self.weekindex_to_price_ohlc_in_sats, + &self.difficultyepoch_to_price_ohlc_in_sats, + &self.monthindex_to_price_ohlc_in_sats, + &self.quarterindex_to_price_ohlc_in_sats, + &self.semesterindex_to_price_ohlc_in_sats, + &self.yearindex_to_price_ohlc_in_sats, + // &self.halvingepoch_to_price_ohlc_in_sats, + &self.decadeindex_to_price_ohlc_in_sats, ], - self.timeindexes_to_close.vecs(), - self.timeindexes_to_high.vecs(), - self.timeindexes_to_low.vecs(), - self.timeindexes_to_open.vecs(), - self.chainindexes_to_close.vecs(), - self.chainindexes_to_high.vecs(), - self.chainindexes_to_low.vecs(), - self.chainindexes_to_open.vecs(), - self.timeindexes_to_close_in_sats.vecs(), - self.timeindexes_to_high_in_sats.vecs(), - self.timeindexes_to_low_in_sats.vecs(), - self.timeindexes_to_open_in_sats.vecs(), - self.chainindexes_to_close_in_sats.vecs(), - self.chainindexes_to_high_in_sats.vecs(), - self.chainindexes_to_low_in_sats.vecs(), - self.chainindexes_to_open_in_sats.vecs(), + self.timeindexes_to_price_close.vecs(), + self.timeindexes_to_price_high.vecs(), + self.timeindexes_to_price_low.vecs(), + self.timeindexes_to_price_open.vecs(), + self.chainindexes_to_price_close.vecs(), + self.chainindexes_to_price_high.vecs(), + self.chainindexes_to_price_low.vecs(), + self.chainindexes_to_price_open.vecs(), + self.timeindexes_to_price_close_in_sats.vecs(), + self.timeindexes_to_price_high_in_sats.vecs(), + self.timeindexes_to_price_low_in_sats.vecs(), + self.timeindexes_to_price_open_in_sats.vecs(), + self.chainindexes_to_price_close_in_sats.vecs(), + self.chainindexes_to_price_high_in_sats.vecs(), + self.chainindexes_to_price_low_in_sats.vecs(), + self.chainindexes_to_price_open_in_sats.vecs(), ] .into_iter() .flatten() diff --git a/crates/brk_computer/src/stateful/address_cohort.rs b/crates/brk_computer/src/stateful/address_cohort.rs index 26a85a107..d5b75dcf9 100644 --- a/crates/brk_computer/src/stateful/address_cohort.rs +++ b/crates/brk_computer/src/stateful/address_cohort.rs @@ -29,8 +29,8 @@ pub struct Vecs { pub inner: common::Vecs, - pub height_to_address_count: EagerVec, - pub indexes_to_address_count: ComputedVecsFromHeight, + pub height_to_addr_count: EagerVec, + pub indexes_to_addr_count: ComputedVecsFromHeight, } impl Vecs { @@ -43,7 +43,7 @@ impl Vecs { indexes: &indexes::Vecs, price: Option<&price::Vecs>, states_path: Option<&Path>, - compute_relative_to_all: bool, + compute_rel_to_all: bool, ) -> Result { let compute_dollars = price.is_some(); @@ -58,15 +58,15 @@ impl Vecs { compute_dollars, ) }), - height_to_address_count: EagerVec::forced_import( + height_to_addr_count: EagerVec::forced_import( db, - &suffix("address_count"), + &suffix("addr_count"), version + VERSION + Version::ZERO, format, )?, - indexes_to_address_count: ComputedVecsFromHeight::forced_import( + indexes_to_addr_count: ComputedVecsFromHeight::forced_import( db, - &suffix("address_count"), + &suffix("addr_count"), Source::None, version + VERSION + Version::ZERO, indexes, @@ -80,7 +80,7 @@ impl Vecs { indexes, price, false, - compute_relative_to_all, + compute_rel_to_all, false, )?, }) @@ -90,7 +90,7 @@ impl Vecs { impl DynCohortVecs for Vecs { fn min_height_vecs_len(&self) -> usize { [ - self.height_to_address_count.len(), + self.height_to_addr_count.len(), self.inner.min_height_vecs_len(), ] .into_iter() @@ -110,8 +110,8 @@ impl DynCohortVecs for Vecs { self.starting_height = Some(starting_height); if let Some(prev_height) = starting_height.decremented() { - self.state.as_mut().unwrap().address_count = *self - .height_to_address_count + self.state.as_mut().unwrap().addr_count = *self + .height_to_addr_count .into_iter() .unwrap_get_inner(prev_height); } @@ -120,9 +120,9 @@ impl DynCohortVecs for Vecs { } fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> { - self.height_to_address_count + self.height_to_addr_count .validate_computed_version_or_reset( - base_version + self.height_to_address_count.inner_version(), + base_version + self.height_to_addr_count.inner_version(), )?; self.inner.validate_computed_versions(base_version) @@ -133,9 +133,9 @@ impl DynCohortVecs for Vecs { return Ok(()); } - self.height_to_address_count.forced_push_at( + self.height_to_addr_count.forced_push_at( height, - self.state.as_ref().unwrap().address_count.into(), + self.state.as_ref().unwrap().addr_count.into(), exit, )?; @@ -162,7 +162,7 @@ impl DynCohortVecs for Vecs { } fn safe_flush_stateful_vecs(&mut self, height: Height, exit: &Exit) -> Result<()> { - self.height_to_address_count.safe_flush(exit)?; + self.height_to_addr_count.safe_flush(exit)?; self.inner .safe_flush_stateful_vecs(height, exit, &mut self.state.as_mut().unwrap().inner) @@ -177,11 +177,11 @@ impl DynCohortVecs for Vecs { starting_indexes: &Indexes, exit: &Exit, ) -> Result<()> { - self.indexes_to_address_count.compute_rest( + self.indexes_to_addr_count.compute_rest( indexes, starting_indexes, exit, - Some(&self.height_to_address_count), + Some(&self.height_to_addr_count), )?; self.inner @@ -191,8 +191,8 @@ impl DynCohortVecs for Vecs { fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { [ self.inner.vecs(), - self.indexes_to_address_count.vecs(), - vec![&self.height_to_address_count], + self.indexes_to_addr_count.vecs(), + vec![&self.height_to_addr_count], ] .concat() } @@ -205,11 +205,11 @@ impl CohortVecs for Vecs { others: &[&Self], exit: &Exit, ) -> Result<()> { - self.height_to_address_count.compute_sum_of_others( + self.height_to_addr_count.compute_sum_of_others( starting_indexes.height, others .iter() - .map(|v| &v.height_to_address_count) + .map(|v| &v.height_to_addr_count) .collect::>() .as_slice(), exit, diff --git a/crates/brk_computer/src/stateful/common.rs b/crates/brk_computer/src/stateful/common.rs index e365fbe82..1140c41a9 100644 --- a/crates/brk_computer/src/stateful/common.rs +++ b/crates/brk_computer/src/stateful/common.rs @@ -27,7 +27,7 @@ pub struct Vecs { pub height_to_supply: EagerVec, pub height_to_utxo_count: EagerVec, // Single - pub dateindex_to_supply_even: Option>, + pub dateindex_to_supply_breakeven: Option>, pub dateindex_to_supply_in_loss: Option>, pub dateindex_to_supply_in_profit: Option>, pub dateindex_to_unrealized_loss: Option>, @@ -38,7 +38,7 @@ pub struct Vecs { pub height_to_min_price_paid: Option>, pub height_to_realized_loss: Option>, pub height_to_realized_profit: Option>, - pub height_to_supply_even: Option>, + pub height_to_supply_breakeven: Option>, pub height_to_supply_in_loss: Option>, pub height_to_supply_in_profit: Option>, pub height_to_unrealized_loss: Option>, @@ -50,22 +50,20 @@ pub struct Vecs { pub indexes_to_coinblocks_destroyed: ComputedVecsFromHeight, pub indexes_to_coindays_destroyed: ComputedVecsFromHeight, - pub dateindex_to_spent_output_profit_ratio: Option>, - pub dateindex_to_spent_output_profit_ratio_7d_ema: Option>, - pub dateindex_to_spent_output_profit_ratio_30d_ema: Option>, - pub dateindex_to_adjusted_spent_output_profit_ratio: Option>, - pub dateindex_to_adjusted_spent_output_profit_ratio_7d_ema: - Option>, - pub dateindex_to_adjusted_spent_output_profit_ratio_30d_ema: - Option>, - pub indexes_to_realized_cap_30d_change: Option>, + pub dateindex_to_sopr: Option>, + pub dateindex_to_sopr_7d_ema: Option>, + pub dateindex_to_sopr_30d_ema: Option>, + pub dateindex_to_adjusted_sopr: Option>, + pub dateindex_to_adjusted_sopr_7d_ema: Option>, + pub dateindex_to_adjusted_sopr_30d_ema: Option>, + pub indexes_to_realized_cap_30d_delta: Option>, pub dateindex_to_sell_side_risk_ratio: Option>, pub dateindex_to_sell_side_risk_ratio_7d_ema: Option>, pub dateindex_to_sell_side_risk_ratio_30d_ema: Option>, pub indexes_to_adjusted_value_created: Option>, pub indexes_to_adjusted_value_destroyed: Option>, - pub indexes_to_negative_realized_loss: Option>, - pub indexes_to_net_realized_profit_and_loss: Option>, + pub indexes_to_neg_realized_loss: Option>, + pub indexes_to_net_realized_pnl: Option>, pub indexes_to_realized_cap: Option>, pub indexes_to_realized_loss: Option>, pub indexes_to_realized_price: Option>, @@ -79,97 +77,86 @@ pub struct Vecs { pub indexes_to_value_destroyed: Option>, pub indexes_to_unrealized_profit: Option>, pub indexes_to_unrealized_loss: Option>, - pub height_to_unrealized_profit_plus_loss: Option>, - pub indexes_to_unrealized_profit_plus_loss: Option>, + pub height_to_unrealized_total_pnl: Option>, + pub indexes_to_unrealized_total_pnl: Option>, pub indexes_to_min_price_paid: Option>, pub indexes_to_max_price_paid: Option>, - pub height_to_halved_supply_value: ComputedHeightValueVecs, - pub indexes_to_halved_supply: ComputedValueVecsFromDateIndex, - pub height_to_negative_unrealized_loss: Option>, - pub indexes_to_negative_unrealized_loss: Option>, - pub height_to_net_unrealized_profit_and_loss: Option>, - pub indexes_to_net_unrealized_profit_and_loss: Option>, - pub height_to_unrealized_profit_relative_to_market_cap: Option>, - pub height_to_unrealized_loss_relative_to_market_cap: Option>, - pub height_to_negative_unrealized_loss_relative_to_market_cap: + pub height_to_supply_half_value: ComputedHeightValueVecs, + pub indexes_to_supply_half: ComputedValueVecsFromDateIndex, + pub height_to_neg_unrealized_loss: Option>, + pub indexes_to_neg_unrealized_loss: Option>, + pub height_to_net_unrealized_pnl: Option>, + pub indexes_to_net_unrealized_pnl: Option>, + pub height_to_unrealized_profit_rel_to_market_cap: Option>, + pub height_to_unrealized_loss_rel_to_market_cap: Option>, + pub height_to_neg_unrealized_loss_rel_to_market_cap: Option>, + pub height_to_net_unrealized_pnl_rel_to_market_cap: Option>, + pub indexes_to_unrealized_profit_rel_to_market_cap: + Option>, + pub indexes_to_unrealized_loss_rel_to_market_cap: Option>, + pub indexes_to_neg_unrealized_loss_rel_to_market_cap: + Option>, + pub indexes_to_net_unrealized_pnl_rel_to_market_cap: + Option>, + pub height_to_unrealized_profit_rel_to_own_market_cap: Option>, + pub height_to_unrealized_loss_rel_to_own_market_cap: Option>, + pub height_to_neg_unrealized_loss_rel_to_own_market_cap: Option>, + pub height_to_net_unrealized_pnl_rel_to_own_market_cap: Option>, + pub indexes_to_unrealized_profit_rel_to_own_market_cap: + Option>, + pub indexes_to_unrealized_loss_rel_to_own_market_cap: + Option>, + pub indexes_to_neg_unrealized_loss_rel_to_own_market_cap: + Option>, + pub indexes_to_net_unrealized_pnl_rel_to_own_market_cap: + Option>, + pub height_to_unrealized_profit_rel_to_own_unrealized_total_pnl: Option>, - pub height_to_net_unrealized_profit_and_loss_relative_to_market_cap: + pub height_to_unrealized_loss_rel_to_own_unrealized_total_pnl: Option>, - pub indexes_to_unrealized_profit_relative_to_market_cap: - Option>, - pub indexes_to_unrealized_loss_relative_to_market_cap: - Option>, - pub indexes_to_negative_unrealized_loss_relative_to_market_cap: - Option>, - pub indexes_to_net_unrealized_profit_and_loss_relative_to_market_cap: - Option>, - pub height_to_unrealized_profit_relative_to_own_market_cap: Option>, - pub height_to_unrealized_loss_relative_to_own_market_cap: Option>, - pub height_to_negative_unrealized_loss_relative_to_own_market_cap: + pub height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl: Option>, - pub height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap: + pub height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl: Option>, - pub indexes_to_unrealized_profit_relative_to_own_market_cap: + pub indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl: Option>, - pub indexes_to_unrealized_loss_relative_to_own_market_cap: + pub indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl: Option>, - pub indexes_to_negative_unrealized_loss_relative_to_own_market_cap: + pub indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl: Option>, - pub indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap: + pub indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl: Option>, - pub height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss: - Option>, - pub indexes_to_realized_profit_relative_to_realized_cap: - Option>, - pub indexes_to_realized_loss_relative_to_realized_cap: - Option>, - pub indexes_to_net_realized_profit_and_loss_relative_to_realized_cap: - Option>, - pub height_to_supply_even_value: Option, + pub indexes_to_realized_cap_rel_to_own_market_cap: Option>, + pub indexes_to_realized_profit_rel_to_realized_cap: Option>, + pub indexes_to_realized_loss_rel_to_realized_cap: Option>, + pub indexes_to_net_realized_pnl_rel_to_realized_cap: Option>, + pub height_to_supply_breakeven_value: Option, pub height_to_supply_in_loss_value: Option, pub height_to_supply_in_profit_value: Option, - pub indexes_to_supply_even: Option, + pub indexes_to_supply_breakeven: Option, pub indexes_to_supply_in_loss: Option, pub indexes_to_supply_in_profit: Option, - pub height_to_supply_even_relative_to_own_supply: Option>, - pub height_to_supply_in_loss_relative_to_own_supply: Option>, - pub height_to_supply_in_profit_relative_to_own_supply: Option>, - pub indexes_to_supply_even_relative_to_own_supply: Option>, - pub indexes_to_supply_in_loss_relative_to_own_supply: + pub height_to_supply_breakeven_rel_to_own_supply: Option>, + pub height_to_supply_in_loss_rel_to_own_supply: Option>, + pub height_to_supply_in_profit_rel_to_own_supply: Option>, + pub indexes_to_supply_breakeven_rel_to_own_supply: Option>, + pub indexes_to_supply_in_loss_rel_to_own_supply: Option>, + pub indexes_to_supply_in_profit_rel_to_own_supply: Option>, + pub indexes_to_supply_rel_to_circulating_supply: Option>, + pub height_to_supply_breakeven_rel_to_circulating_supply: Option>, + pub height_to_supply_in_loss_rel_to_circulating_supply: Option>, + pub height_to_supply_in_profit_rel_to_circulating_supply: Option>, + pub indexes_to_supply_breakeven_rel_to_circulating_supply: Option>, - pub indexes_to_supply_in_profit_relative_to_own_supply: + pub indexes_to_supply_in_loss_rel_to_circulating_supply: Option>, - pub indexes_to_supply_relative_to_circulating_supply: Option>, - pub height_to_supply_even_relative_to_circulating_supply: Option>, - pub height_to_supply_in_loss_relative_to_circulating_supply: - Option>, - pub height_to_supply_in_profit_relative_to_circulating_supply: - Option>, - pub indexes_to_supply_even_relative_to_circulating_supply: + pub indexes_to_supply_in_profit_rel_to_circulating_supply: Option>, - pub indexes_to_supply_in_loss_relative_to_circulating_supply: - Option>, - pub indexes_to_supply_in_profit_relative_to_circulating_supply: - Option>, - pub indexes_to_net_realized_profit_and_loss_cumulative_30d_change: + pub indexes_to_net_realized_pnl_cumulative_30d_delta: Option>, - pub indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap: + pub indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap: Option>, - pub indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap: + pub indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_market_cap: Option>, } @@ -183,7 +170,7 @@ impl Vecs { indexes: &indexes::Vecs, price: Option<&price::Vecs>, extended: bool, - compute_relative_to_all: bool, + compute_rel_to_all: bool, compute_adjusted: bool, ) -> Result { let compute_dollars = price.is_some(); @@ -202,10 +189,10 @@ impl Vecs { .unwrap() }); - let dateindex_to_supply_even = compute_dollars.then(|| { + let dateindex_to_supply_breakeven = compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("supply_even"), + &suffix("supply_breakeven"), version + VERSION + Version::ZERO, format, ) @@ -256,7 +243,10 @@ impl Vecs { ComputedValueVecsFromDateIndex::forced_import( db, &suffix("supply_in_profit"), - dateindex_to_supply_in_profit.as_ref().map(|v | v.boxed_clone()).into(), + dateindex_to_supply_in_profit + .as_ref() + .map(|v| v.boxed_clone()) + .into(), version + VERSION + Version::ZERO, VecBuilderOptions::default().add_last(), compute_dollars, @@ -265,20 +255,23 @@ impl Vecs { .unwrap() }), dateindex_to_supply_in_profit, - height_to_supply_even: compute_dollars.then(|| { + height_to_supply_breakeven: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("supply_even"), + &suffix("supply_breakeven"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - indexes_to_supply_even: compute_dollars.then(|| { + indexes_to_supply_breakeven: compute_dollars.then(|| { ComputedValueVecsFromDateIndex::forced_import( db, - &suffix("supply_even"), - dateindex_to_supply_even.as_ref().map(|v | v.boxed_clone()).into(), + &suffix("supply_breakeven"), + dateindex_to_supply_breakeven + .as_ref() + .map(|v| v.boxed_clone()) + .into(), version + VERSION + Version::ZERO, VecBuilderOptions::default().add_last(), compute_dollars, @@ -286,7 +279,7 @@ impl Vecs { ) .unwrap() }), - dateindex_to_supply_even, + dateindex_to_supply_breakeven, height_to_supply_in_loss: compute_dollars.then(|| { EagerVec::forced_import( db, @@ -300,7 +293,10 @@ impl Vecs { ComputedValueVecsFromDateIndex::forced_import( db, &suffix("supply_in_loss"), - dateindex_to_supply_in_loss.as_ref().map(|v | v.boxed_clone()).into(), + dateindex_to_supply_in_loss + .as_ref() + .map(|v| v.boxed_clone()) + .into(), version + VERSION + Version::ZERO, VecBuilderOptions::default().add_last(), compute_dollars, @@ -322,7 +318,10 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( db, &suffix("unrealized_profit"), - dateindex_to_unrealized_profit.as_ref().map(|v | v.boxed_clone()).into(), + dateindex_to_unrealized_profit + .as_ref() + .map(|v| v.boxed_clone()) + .into(), version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), @@ -361,25 +360,28 @@ impl Vecs { ComputedVecsFromDateIndex::forced_import( db, &suffix("unrealized_loss"), - dateindex_to_unrealized_loss.as_ref().map(|v | v.boxed_clone()).into(), + dateindex_to_unrealized_loss + .as_ref() + .map(|v| v.boxed_clone()) + .into(), version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), ) .unwrap() }), - height_to_unrealized_profit_plus_loss: compute_dollars.then(|| { + height_to_unrealized_total_pnl: compute_dollars.then(|| { EagerVec::forced_import_compressed( db, - &suffix("unrealized_profit_plus_loss"), + &suffix("unrealized_total_pnl"), version + VERSION + Version::ZERO, ) .unwrap() }), - indexes_to_unrealized_profit_plus_loss: compute_dollars.then(|| { + indexes_to_unrealized_total_pnl: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("unrealized_profit_plus_loss"), + &suffix("unrealized_total_pnl"), Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -473,7 +475,7 @@ impl Vecs { &suffix("realized_price"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() @@ -489,6 +491,19 @@ impl Vecs { ) .unwrap() }), + indexes_to_realized_cap_rel_to_own_market_cap: (compute_dollars && extended).then( + || { + ComputedVecsFromHeight::forced_import( + db, + &suffix("realized_cap_rel_to_own_market_cap"), + Source::Compute, + version + VERSION + Version::ZERO, + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }, + ), height_to_realized_profit: compute_dollars.then(|| { EagerVec::forced_import( db, @@ -504,10 +519,8 @@ impl Vecs { &suffix("realized_profit"), Source::None, version + VERSION + Version::ZERO, - indexes, - VecBuilderOptions::default() - .add_sum() - .add_cumulative(), + indexes, + VecBuilderOptions::default().add_sum().add_cumulative(), ) .unwrap() }), @@ -526,20 +539,18 @@ impl Vecs { &suffix("realized_loss"), Source::None, version + VERSION + Version::ZERO, - indexes, - VecBuilderOptions::default() - .add_sum() - .add_cumulative(), + indexes, + VecBuilderOptions::default().add_sum().add_cumulative(), ) .unwrap() }), - indexes_to_negative_realized_loss: compute_dollars.then(|| { + indexes_to_neg_realized_loss: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( db, - &suffix("negative_realized_loss"), + &suffix("neg_realized_loss"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_sum().add_cumulative(), ) .unwrap() @@ -559,7 +570,7 @@ impl Vecs { &suffix("value_created"), Source::None, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() @@ -570,7 +581,7 @@ impl Vecs { &suffix("realized_value"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() @@ -590,7 +601,7 @@ impl Vecs { &suffix("adjusted_value_created"), Source::None, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() @@ -610,7 +621,7 @@ impl Vecs { &suffix("value_destroyed"), Source::None, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() @@ -630,32 +641,30 @@ impl Vecs { &suffix("adjusted_value_destroyed"), Source::None, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() }), - indexes_to_realized_cap_30d_change: compute_dollars.then(|| { + indexes_to_realized_cap_30d_delta: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("realized_cap_30d_change"), + &suffix("realized_cap_30d_delta"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() }), - indexes_to_net_realized_profit_and_loss: compute_dollars.then(|| { + indexes_to_net_realized_pnl: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( db, - &suffix("net_realized_profit_and_loss"), + &suffix("net_realized_pnl"), Source::Compute, version + VERSION + Version::ZERO, - indexes, - VecBuilderOptions::default() - .add_sum() - .add_cumulative(), + indexes, + VecBuilderOptions::default().add_sum().add_cumulative(), ) .unwrap() }), @@ -686,444 +695,434 @@ impl Vecs { ) .unwrap() }), - dateindex_to_spent_output_profit_ratio: compute_dollars.then(|| { + dateindex_to_sopr: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("spent_output_profit_ratio"), + &suffix("sopr"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - dateindex_to_spent_output_profit_ratio_7d_ema: compute_dollars.then(|| { + dateindex_to_sopr_7d_ema: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("spent_output_profit_ratio_7d_ema"), + &suffix("sopr_7d_ema"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - dateindex_to_spent_output_profit_ratio_30d_ema: compute_dollars.then(|| { + dateindex_to_sopr_30d_ema: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("spent_output_profit_ratio_30d_ema"), + &suffix("sopr_30d_ema"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - dateindex_to_adjusted_spent_output_profit_ratio: (compute_dollars && compute_adjusted).then(|| { + dateindex_to_adjusted_sopr: (compute_dollars && compute_adjusted).then(|| { EagerVec::forced_import( db, - &suffix("adjusted_spent_output_profit_ratio"), + &suffix("adjusted_sopr"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - dateindex_to_adjusted_spent_output_profit_ratio_7d_ema: (compute_dollars && compute_adjusted).then(|| { + dateindex_to_adjusted_sopr_7d_ema: (compute_dollars && compute_adjusted).then(|| { EagerVec::forced_import( db, - &suffix("adjusted_spent_output_profit_ratio_7d_ema"), + &suffix("adjusted_sopr_7d_ema"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - dateindex_to_adjusted_spent_output_profit_ratio_30d_ema: (compute_dollars && compute_adjusted).then(|| { + dateindex_to_adjusted_sopr_30d_ema: (compute_dollars && compute_adjusted).then(|| { EagerVec::forced_import( db, - &suffix("adjusted_spent_output_profit_ratio_30d_ema"), + &suffix("adjusted_sopr_30d_ema"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - height_to_halved_supply_value: ComputedHeightValueVecs::forced_import( + height_to_supply_half_value: ComputedHeightValueVecs::forced_import( db, - &suffix("halved_supply"), + &suffix("supply_half"), Source::Compute, version + VERSION + Version::ZERO, format, compute_dollars, )?, - indexes_to_halved_supply: ComputedValueVecsFromDateIndex::forced_import( + indexes_to_supply_half: ComputedValueVecsFromDateIndex::forced_import( db, - &suffix("halved_supply"), + &suffix("supply_half"), Source::Compute, version + VERSION + Version::ZERO, VecBuilderOptions::default().add_last(), compute_dollars, - indexes, + indexes, )?, - height_to_negative_unrealized_loss: compute_dollars.then(|| { + height_to_neg_unrealized_loss: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("negative_unrealized_loss"), + &suffix("neg_unrealized_loss"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - indexes_to_negative_unrealized_loss: compute_dollars.then(|| { + indexes_to_neg_unrealized_loss: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("negative_unrealized_loss"), + &suffix("neg_unrealized_loss"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() }), - height_to_net_unrealized_profit_and_loss: compute_dollars.then(|| { + height_to_net_unrealized_pnl: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("net_unrealized_profit_and_loss"), + &suffix("net_unrealized_pnl"), version + VERSION + Version::ZERO, format, ) .unwrap() }), - indexes_to_net_unrealized_profit_and_loss: compute_dollars.then(|| { + indexes_to_net_unrealized_pnl: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("net_unrealized_profit_and_loss"), + &suffix("net_unrealized_pnl"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() }), - height_to_unrealized_profit_relative_to_market_cap: compute_dollars.then( - || { + height_to_unrealized_profit_rel_to_market_cap: compute_dollars.then(|| { + EagerVec::forced_import( + db, + &suffix("unrealized_profit_rel_to_market_cap"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }), + height_to_unrealized_loss_rel_to_market_cap: compute_dollars.then(|| { + EagerVec::forced_import( + db, + &suffix("unrealized_loss_rel_to_market_cap"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }), + height_to_neg_unrealized_loss_rel_to_market_cap: compute_dollars.then(|| { + EagerVec::forced_import( + db, + &suffix("neg_unrealized_loss_rel_to_market_cap"), + version + VERSION + Version::ZERO, + format, + ) + .unwrap() + }), + height_to_net_unrealized_pnl_rel_to_market_cap: compute_dollars.then(|| { + EagerVec::forced_import( + db, + &suffix("net_unrealized_pnl_rel_to_market_cap"), + version + VERSION + Version::ONE, + format, + ) + .unwrap() + }), + indexes_to_unrealized_profit_rel_to_market_cap: compute_dollars.then(|| { + ComputedVecsFromDateIndex::forced_import( + db, + &suffix("unrealized_profit_rel_to_market_cap"), + Source::Compute, + version + VERSION + Version::ONE, + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }), + indexes_to_unrealized_loss_rel_to_market_cap: compute_dollars.then(|| { + ComputedVecsFromDateIndex::forced_import( + db, + &suffix("unrealized_loss_rel_to_market_cap"), + Source::Compute, + version + VERSION + Version::ONE, + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }), + indexes_to_neg_unrealized_loss_rel_to_market_cap: compute_dollars.then(|| { + ComputedVecsFromDateIndex::forced_import( + db, + &suffix("neg_unrealized_loss_rel_to_market_cap"), + Source::Compute, + version + VERSION + Version::ONE, + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }), + indexes_to_net_unrealized_pnl_rel_to_market_cap: compute_dollars.then(|| { + ComputedVecsFromDateIndex::forced_import( + db, + &suffix("net_unrealized_pnl_rel_to_market_cap"), + Source::Compute, + version + VERSION + Version::ONE, + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }), + height_to_unrealized_profit_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { EagerVec::forced_import( db, - &suffix("unrealized_profit_relative_to_market_cap"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }, - ), - height_to_unrealized_loss_relative_to_market_cap: compute_dollars.then( - || { - EagerVec::forced_import( - db, - &suffix("unrealized_loss_relative_to_market_cap"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }, - ), - height_to_negative_unrealized_loss_relative_to_market_cap: compute_dollars.then( - || { - EagerVec::forced_import( - db, - &suffix("negative_unrealized_loss_relative_to_market_cap"), - version + VERSION + Version::ZERO, - format, - ) - .unwrap() - }, - ), - height_to_net_unrealized_profit_and_loss_relative_to_market_cap: compute_dollars.then( - || { - EagerVec::forced_import( - db, - &suffix("net_unrealized_profit_and_loss_relative_to_market_cap"), + &suffix("unrealized_profit_rel_to_own_market_cap"), version + VERSION + Version::ONE, format, ) .unwrap() - }, - ), - indexes_to_unrealized_profit_relative_to_market_cap: compute_dollars.then( - || { - ComputedVecsFromDateIndex::forced_import( - db, - &suffix("unrealized_profit_relative_to_market_cap"), - Source::Compute, - version + VERSION + Version::ONE, - indexes, - VecBuilderOptions::default().add_last(), - ) - .unwrap() - }, - ), - indexes_to_unrealized_loss_relative_to_market_cap: compute_dollars.then( - || { - ComputedVecsFromDateIndex::forced_import( - db, - &suffix("unrealized_loss_relative_to_market_cap"), - Source::Compute, - version + VERSION + Version::ONE, - indexes, - VecBuilderOptions::default().add_last(), - ) - .unwrap() - }, - ), - indexes_to_negative_unrealized_loss_relative_to_market_cap: compute_dollars.then( - || { - ComputedVecsFromDateIndex::forced_import( - db, - &suffix("negative_unrealized_loss_relative_to_market_cap"), - Source::Compute, - version + VERSION + Version::ONE, - indexes, - VecBuilderOptions::default().add_last(), - ) - .unwrap() - }, - ), - indexes_to_net_unrealized_profit_and_loss_relative_to_market_cap: compute_dollars.then( - || { - ComputedVecsFromDateIndex::forced_import( - db, - &suffix("net_unrealized_profit_and_loss_relative_to_market_cap"), - Source::Compute, - version + VERSION + Version::ONE, - indexes, - VecBuilderOptions::default().add_last(), - ) - .unwrap() - }, - ), - height_to_unrealized_profit_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + height_to_unrealized_loss_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { EagerVec::forced_import( db, - &suffix("unrealized_profit_relative_to_own_market_cap"), + &suffix("unrealized_loss_rel_to_own_market_cap"), version + VERSION + Version::ONE, format, ) .unwrap() - }, - ), - height_to_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + height_to_neg_unrealized_loss_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { EagerVec::forced_import( db, - &suffix("unrealized_loss_relative_to_own_market_cap"), + &suffix("neg_unrealized_loss_rel_to_own_market_cap"), version + VERSION + Version::ONE, format, ) .unwrap() - }, - ), - height_to_negative_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + height_to_net_unrealized_pnl_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { EagerVec::forced_import( db, - &suffix("negative_unrealized_loss_relative_to_own_market_cap"), - version + VERSION + Version::ONE, - format, - ) - .unwrap() - }, - ), - height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { - EagerVec::forced_import( - db, - &suffix("net_unrealized_profit_and_loss_relative_to_own_market_cap"), + &suffix("net_unrealized_pnl_rel_to_own_market_cap"), version + VERSION + Version::TWO, format, ) .unwrap() - }, - ), - indexes_to_unrealized_profit_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + indexes_to_unrealized_profit_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("unrealized_profit_relative_to_own_market_cap"), + &suffix("unrealized_profit_rel_to_own_market_cap"), Source::Compute, version + VERSION + Version::TWO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + indexes_to_unrealized_loss_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("unrealized_loss_relative_to_own_market_cap"), + &suffix("unrealized_loss_rel_to_own_market_cap"), Source::Compute, version + VERSION + Version::TWO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_negative_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + indexes_to_neg_unrealized_loss_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("negative_unrealized_loss_relative_to_own_market_cap"), + &suffix("neg_unrealized_loss_rel_to_own_market_cap"), Source::Compute, version + VERSION + Version::TWO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then( - || { + }), + indexes_to_net_unrealized_pnl_rel_to_own_market_cap: (compute_dollars + && extended + && compute_rel_to_all) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("net_unrealized_profit_and_loss_relative_to_own_market_cap"), + &suffix("net_unrealized_pnl_rel_to_own_market_cap"), Source::Compute, version + VERSION + Version::TWO, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + height_to_unrealized_profit_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { EagerVec::forced_import( db, - &suffix("unrealized_profit_relative_to_own_unrealized_profit_plus_loss"), + &suffix("unrealized_profit_rel_to_own_unrealized_total_pnl"), version + VERSION + Version::ZERO, format, ) .unwrap() - }, - ), - height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + height_to_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { EagerVec::forced_import( db, - &suffix("unrealized_loss_relative_to_own_unrealized_profit_plus_loss"), + &suffix("unrealized_loss_rel_to_own_unrealized_total_pnl"), version + VERSION + Version::ZERO, format, ) .unwrap() - }, - ), - height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { EagerVec::forced_import( db, - &suffix("negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss"), + &suffix("neg_unrealized_loss_rel_to_own_unrealized_total_pnl"), version + VERSION + Version::ZERO, format, ) .unwrap() - }, - ), - height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { EagerVec::forced_import( db, - &suffix("net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss"), + &suffix("net_unrealized_pnl_rel_to_own_unrealized_total_pnl"), version + VERSION + Version::ONE, format, ) .unwrap() - }, - ), - indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("unrealized_profit_relative_to_own_unrealized_profit_plus_loss"), + &suffix("unrealized_profit_rel_to_own_unrealized_total_pnl"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("unrealized_loss_relative_to_own_unrealized_profit_plus_loss"), + &suffix("unrealized_loss_rel_to_own_unrealized_total_pnl"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss"), + &suffix("neg_unrealized_loss_rel_to_own_unrealized_total_pnl"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then( - || { + }), + indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl: (compute_dollars + && extended) + .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss"), + &suffix("net_unrealized_pnl_rel_to_own_unrealized_total_pnl"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() - }, - ), - indexes_to_realized_profit_relative_to_realized_cap: compute_dollars.then(|| { + }), + indexes_to_realized_profit_rel_to_realized_cap: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( db, - &suffix("realized_profit_relative_to_realized_cap"), + &suffix("realized_profit_rel_to_realized_cap"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() }), - indexes_to_realized_loss_relative_to_realized_cap: compute_dollars.then(|| { + indexes_to_realized_loss_rel_to_realized_cap: compute_dollars.then(|| { ComputedVecsFromHeight::forced_import( db, - &suffix("realized_loss_relative_to_realized_cap"), + &suffix("realized_loss_rel_to_realized_cap"), Source::Compute, version + VERSION + Version::ZERO, - indexes, + indexes, VecBuilderOptions::default().add_sum(), ) .unwrap() }), - indexes_to_net_realized_profit_and_loss_relative_to_realized_cap: compute_dollars.then( - || { - ComputedVecsFromHeight::forced_import( - db, - &suffix("net_realized_profit_and_loss_relative_to_realized_cap"), - Source::Compute, - version + VERSION + Version::ONE, - indexes, - VecBuilderOptions::default().add_sum(), - ) - .unwrap() - }, - ), - height_to_supply_even_value: compute_dollars.then(|| { + indexes_to_net_realized_pnl_rel_to_realized_cap: compute_dollars.then(|| { + ComputedVecsFromHeight::forced_import( + db, + &suffix("net_realized_pnl_rel_to_realized_cap"), + Source::Compute, + version + VERSION + Version::ONE, + indexes, + VecBuilderOptions::default().add_sum(), + ) + .unwrap() + }), + height_to_supply_breakeven_value: compute_dollars.then(|| { ComputedHeightValueVecs::forced_import( db, - &suffix("supply_even"), + &suffix("supply_breakeven"), Source::None, version + VERSION + Version::ZERO, format, @@ -1153,37 +1152,37 @@ impl Vecs { ) .unwrap() }), - height_to_supply_even_relative_to_own_supply: compute_dollars.then(|| { + height_to_supply_breakeven_rel_to_own_supply: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("supply_even_relative_to_own_supply"), + &suffix("supply_breakeven_rel_to_own_supply"), version + VERSION + Version::ONE, format, ) .unwrap() }), - height_to_supply_in_loss_relative_to_own_supply: compute_dollars.then(|| { + height_to_supply_in_loss_rel_to_own_supply: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("supply_in_loss_relative_to_own_supply"), + &suffix("supply_in_loss_rel_to_own_supply"), version + VERSION + Version::ONE, format, ) .unwrap() }), - height_to_supply_in_profit_relative_to_own_supply: compute_dollars.then(|| { + height_to_supply_in_profit_rel_to_own_supply: compute_dollars.then(|| { EagerVec::forced_import( db, - &suffix("supply_in_profit_relative_to_own_supply"), + &suffix("supply_in_profit_rel_to_own_supply"), version + VERSION + Version::ONE, format, ) .unwrap() }), - indexes_to_supply_even_relative_to_own_supply: compute_dollars.then(|| { + indexes_to_supply_breakeven_rel_to_own_supply: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("supply_even_relative_to_own_supply"), + &suffix("supply_breakeven_rel_to_own_supply"), Source::Compute, version + VERSION + Version::ONE, indexes, @@ -1191,10 +1190,10 @@ impl Vecs { ) .unwrap() }), - indexes_to_supply_in_loss_relative_to_own_supply: compute_dollars.then(|| { + indexes_to_supply_in_loss_rel_to_own_supply: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("supply_in_loss_relative_to_own_supply"), + &suffix("supply_in_loss_rel_to_own_supply"), Source::Compute, version + VERSION + Version::ONE, indexes, @@ -1202,10 +1201,10 @@ impl Vecs { ) .unwrap() }), - indexes_to_supply_in_profit_relative_to_own_supply: compute_dollars.then(|| { + indexes_to_supply_in_profit_rel_to_own_supply: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("supply_in_profit_relative_to_own_supply"), + &suffix("supply_in_profit_rel_to_own_supply"), Source::Compute, version + VERSION + Version::ONE, indexes, @@ -1213,10 +1212,10 @@ impl Vecs { ) .unwrap() }), - indexes_to_supply_relative_to_circulating_supply: compute_relative_to_all.then(|| { + indexes_to_supply_rel_to_circulating_supply: compute_rel_to_all.then(|| { ComputedVecsFromHeight::forced_import( db, - &suffix("supply_relative_to_circulating_supply"), + &suffix("supply_rel_to_circulating_supply"), Source::Compute, version + VERSION + Version::ONE, indexes, @@ -1224,74 +1223,74 @@ impl Vecs { ) .unwrap() }), - height_to_supply_even_relative_to_circulating_supply: (compute_relative_to_all + height_to_supply_breakeven_rel_to_circulating_supply: (compute_rel_to_all && compute_dollars) .then(|| { EagerVec::forced_import( db, - &suffix("supply_even_relative_to_circulating_supply"), + &suffix("supply_breakeven_rel_to_circulating_supply"), version + VERSION + Version::ONE, format, ) .unwrap() }), - height_to_supply_in_loss_relative_to_circulating_supply: (compute_relative_to_all + height_to_supply_in_loss_rel_to_circulating_supply: (compute_rel_to_all && compute_dollars) .then(|| { EagerVec::forced_import( db, - &suffix("supply_in_loss_relative_to_circulating_supply"), + &suffix("supply_in_loss_rel_to_circulating_supply"), version + VERSION + Version::ONE, format, ) .unwrap() }), - height_to_supply_in_profit_relative_to_circulating_supply: (compute_relative_to_all + height_to_supply_in_profit_rel_to_circulating_supply: (compute_rel_to_all && compute_dollars) .then(|| { EagerVec::forced_import( db, - &suffix("supply_in_profit_relative_to_circulating_supply"), + &suffix("supply_in_profit_rel_to_circulating_supply"), version + VERSION + Version::ONE, format, ) .unwrap() }), - indexes_to_supply_even_relative_to_circulating_supply: (compute_relative_to_all + indexes_to_supply_breakeven_rel_to_circulating_supply: (compute_rel_to_all && compute_dollars) .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("supply_even_relative_to_circulating_supply"), + &suffix("supply_breakeven_rel_to_circulating_supply"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() }), - indexes_to_supply_in_loss_relative_to_circulating_supply: (compute_relative_to_all + indexes_to_supply_in_loss_rel_to_circulating_supply: (compute_rel_to_all && compute_dollars) .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("supply_in_loss_relative_to_circulating_supply"), + &suffix("supply_in_loss_rel_to_circulating_supply"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() }), - indexes_to_supply_in_profit_relative_to_circulating_supply: (compute_relative_to_all + indexes_to_supply_in_profit_rel_to_circulating_supply: (compute_rel_to_all && compute_dollars) .then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("supply_in_profit_relative_to_circulating_supply"), + &suffix("supply_in_profit_rel_to_circulating_supply"), Source::Compute, version + VERSION + Version::ONE, - indexes, + indexes, VecBuilderOptions::default().add_last(), ) .unwrap() @@ -1321,42 +1320,44 @@ impl Vecs { &suffix("coindays_destroyed"), Source::Compute, version + VERSION + Version::TWO, - indexes, + indexes, VecBuilderOptions::default().add_sum().add_cumulative(), )?, - indexes_to_net_realized_profit_and_loss_cumulative_30d_change: compute_dollars.then(|| { + indexes_to_net_realized_pnl_cumulative_30d_delta: compute_dollars.then(|| { ComputedVecsFromDateIndex::forced_import( db, - &suffix("net_realized_profit_and_loss_cumulative_30d_change"), + &suffix("net_realized_pnl_cumulative_30d_delta"), Source::Compute, version + VERSION + Version::new(3), - indexes, - VecBuilderOptions::default().add_last() - ) - .unwrap() - }), - indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap: compute_dollars.then(|| { - ComputedVecsFromDateIndex::forced_import( - db, - &suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap"), - Source::Compute, - version + VERSION + Version::new(3), - indexes, - VecBuilderOptions::default().add_last() - ) - .unwrap() - }), - indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap: compute_dollars.then(|| { - ComputedVecsFromDateIndex::forced_import( - db, - &suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap"), - Source::Compute, - version + VERSION + Version::new(3), - indexes, - VecBuilderOptions::default().add_last() + indexes, + VecBuilderOptions::default().add_last(), ) .unwrap() }), + indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap: compute_dollars + .then(|| { + ComputedVecsFromDateIndex::forced_import( + db, + &suffix("net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap"), + Source::Compute, + version + VERSION + Version::new(3), + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }), + indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_market_cap: compute_dollars + .then(|| { + ComputedVecsFromDateIndex::forced_import( + db, + &suffix("net_realized_pnl_cumulative_30d_delta_rel_to_market_cap"), + Source::Compute, + version + VERSION + Version::new(3), + indexes, + VecBuilderOptions::default().add_last(), + ) + .unwrap() + }), }) } @@ -1391,7 +1392,7 @@ impl Vecs { self.height_to_supply_in_loss .as_ref() .map_or(usize::MAX, |v| v.len()), - self.height_to_supply_even + self.height_to_supply_breakeven .as_ref() .map_or(usize::MAX, |v| v.len()), self.height_to_unrealized_profit @@ -1536,13 +1537,16 @@ impl Vecs { .validate_computed_version_or_reset( base_version + height_to_supply_in_loss_inner_version, )?; - let height_to_supply_even_inner_version = - self.height_to_supply_even.as_ref().unwrap().inner_version(); - self.height_to_supply_even + let height_to_supply_breakeven_inner_version = self + .height_to_supply_breakeven + .as_ref() + .unwrap() + .inner_version(); + self.height_to_supply_breakeven .as_mut() .unwrap() .validate_computed_version_or_reset( - base_version + height_to_supply_even_inner_version, + base_version + height_to_supply_breakeven_inner_version, )?; let height_to_unrealized_profit_inner_version = self .height_to_unrealized_profit @@ -1588,16 +1592,16 @@ impl Vecs { .validate_computed_version_or_reset( base_version + dateindex_to_supply_in_loss_inner_version, )?; - let dateindex_to_supply_even_inner_version = self - .dateindex_to_supply_even + let dateindex_to_supply_breakeven_inner_version = self + .dateindex_to_supply_breakeven .as_ref() .unwrap() .inner_version(); - self.dateindex_to_supply_even + self.dateindex_to_supply_breakeven .as_mut() .unwrap() .validate_computed_version_or_reset( - base_version + dateindex_to_supply_even_inner_version, + base_version + dateindex_to_supply_breakeven_inner_version, )?; let dateindex_to_unrealized_profit_inner_version = self .dateindex_to_unrealized_profit @@ -1772,10 +1776,10 @@ impl Vecs { let (height_unrealized_state, date_unrealized_state) = state.compute_unrealized_states(height_price, date_price.unwrap()); - self.height_to_supply_even + self.height_to_supply_breakeven .as_mut() .unwrap() - .forced_push_at(height, height_unrealized_state.supply_even, exit)?; + .forced_push_at(height, height_unrealized_state.supply_breakeven, exit)?; self.height_to_supply_in_profit .as_mut() .unwrap() @@ -1796,10 +1800,10 @@ impl Vecs { if let Some(date_unrealized_state) = date_unrealized_state { let dateindex = dateindex.unwrap(); - self.dateindex_to_supply_even + self.dateindex_to_supply_breakeven .as_mut() .unwrap() - .forced_push_at(dateindex, date_unrealized_state.supply_even, exit)?; + .forced_push_at(dateindex, date_unrealized_state.supply_breakeven, exit)?; self.dateindex_to_supply_in_profit .as_mut() .unwrap() @@ -1859,7 +1863,7 @@ impl Vecs { .as_mut() .unwrap() .safe_flush(exit)?; - self.height_to_supply_even + self.height_to_supply_breakeven .as_mut() .unwrap() .safe_flush(exit)?; @@ -1879,7 +1883,7 @@ impl Vecs { .as_mut() .unwrap() .safe_flush(exit)?; - self.dateindex_to_supply_even + self.dateindex_to_supply_breakeven .as_mut() .unwrap() .safe_flush(exit)?; @@ -2067,14 +2071,14 @@ impl Vecs { .as_slice(), exit, )?; - self.height_to_supply_even + self.height_to_supply_breakeven .as_mut() .unwrap() .compute_sum_of_others( starting_indexes.height, others .iter() - .map(|v| v.height_to_supply_even.as_ref().unwrap()) + .map(|v| v.height_to_supply_breakeven.as_ref().unwrap()) .collect::>() .as_slice(), exit, @@ -2127,14 +2131,14 @@ impl Vecs { .as_slice(), exit, )?; - self.dateindex_to_supply_even + self.dateindex_to_supply_breakeven .as_mut() .unwrap() .compute_sum_of_others( starting_indexes.dateindex, others .iter() - .map(|v| v.dateindex_to_supply_even.as_ref().unwrap()) + .map(|v| v.dateindex_to_supply_breakeven.as_ref().unwrap()) .collect::>() .as_slice(), exit, @@ -2277,7 +2281,7 @@ impl Vecs { Some(&self.height_to_utxo_count), )?; - self.height_to_halved_supply_value.compute_all( + self.height_to_supply_half_value.compute_all( indexer, indexes, price, @@ -2294,7 +2298,7 @@ impl Vecs { }, )?; - self.indexes_to_halved_supply.compute_all( + self.indexes_to_supply_half.compute_all( indexer, indexes, price, @@ -2361,10 +2365,7 @@ impl Vecs { dateindex_to_realized_cap: Option<&impl AnyIterableVec>, exit: &Exit, ) -> Result<()> { - if let Some(v) = self - .indexes_to_supply_relative_to_circulating_supply - .as_mut() - { + if let Some(v) = self.indexes_to_supply_rel_to_circulating_supply.as_mut() { v.compute_all( indexer, indexes, @@ -2450,7 +2451,7 @@ impl Vecs { Some(self.height_to_realized_loss.as_ref().unwrap()), )?; - self.indexes_to_negative_realized_loss + self.indexes_to_neg_realized_loss .as_mut() .unwrap() .compute_all( @@ -2489,7 +2490,7 @@ impl Vecs { Some(self.height_to_value_destroyed.as_ref().unwrap()), )?; - self.indexes_to_realized_cap_30d_change + self.indexes_to_realized_cap_30d_delta .as_mut() .unwrap() .compute_all( @@ -2512,7 +2513,7 @@ impl Vecs { }, )?; - self.indexes_to_net_realized_profit_and_loss + self.indexes_to_net_realized_pnl .as_mut() .unwrap() .compute_all( @@ -2550,44 +2551,37 @@ impl Vecs { }, )?; - self.dateindex_to_spent_output_profit_ratio - .as_mut() - .unwrap() - .compute_divide( - starting_indexes.dateindex, - self.indexes_to_value_created - .as_ref() - .unwrap() - .dateindex - .unwrap_sum(), - self.indexes_to_value_destroyed - .as_ref() - .unwrap() - .dateindex - .unwrap_sum(), - exit, - )?; + self.dateindex_to_sopr.as_mut().unwrap().compute_divide( + starting_indexes.dateindex, + self.indexes_to_value_created + .as_ref() + .unwrap() + .dateindex + .unwrap_sum(), + self.indexes_to_value_destroyed + .as_ref() + .unwrap() + .dateindex + .unwrap_sum(), + exit, + )?; - self.dateindex_to_spent_output_profit_ratio_7d_ema + self.dateindex_to_sopr_7d_ema .as_mut() .unwrap() .compute_ema( starting_indexes.dateindex, - self.dateindex_to_spent_output_profit_ratio - .as_ref() - .unwrap(), + self.dateindex_to_sopr.as_ref().unwrap(), 7, exit, )?; - self.dateindex_to_spent_output_profit_ratio_30d_ema + self.dateindex_to_sopr_30d_ema .as_mut() .unwrap() .compute_ema( starting_indexes.dateindex, - self.dateindex_to_spent_output_profit_ratio - .as_ref() - .unwrap(), + self.dateindex_to_sopr.as_ref().unwrap(), 30, exit, )?; @@ -2652,14 +2646,17 @@ impl Vecs { exit, Some(self.dateindex_to_supply_in_loss.as_ref().unwrap()), )?; - self.indexes_to_supply_even.as_mut().unwrap().compute_rest( - indexer, - indexes, - price, - starting_indexes, - exit, - Some(self.dateindex_to_supply_even.as_ref().unwrap()), - )?; + self.indexes_to_supply_breakeven + .as_mut() + .unwrap() + .compute_rest( + indexer, + indexes, + price, + starting_indexes, + exit, + Some(self.dateindex_to_supply_breakeven.as_ref().unwrap()), + )?; self.indexes_to_unrealized_profit .as_mut() .unwrap() @@ -2676,7 +2673,7 @@ impl Vecs { exit, Some(self.dateindex_to_unrealized_loss.as_ref().unwrap()), )?; - self.height_to_unrealized_profit_plus_loss + self.height_to_unrealized_total_pnl .as_mut() .unwrap() .compute_add( @@ -2685,7 +2682,7 @@ impl Vecs { self.height_to_unrealized_loss.as_ref().unwrap(), exit, )?; - self.indexes_to_unrealized_profit_plus_loss + self.indexes_to_unrealized_total_pnl .as_mut() .unwrap() .compute_all( @@ -2723,7 +2720,7 @@ impl Vecs { Some(self.height_to_max_price_paid.as_ref().unwrap()), )?; - self.height_to_negative_unrealized_loss + self.height_to_neg_unrealized_loss .as_mut() .unwrap() .compute_transform( @@ -2732,7 +2729,7 @@ impl Vecs { |(h, v, ..)| (h, v * -1_i64), exit, )?; - self.indexes_to_negative_unrealized_loss + self.indexes_to_neg_unrealized_loss .as_mut() .unwrap() .compute_all( @@ -2750,7 +2747,7 @@ impl Vecs { Ok(()) }, )?; - self.height_to_net_unrealized_profit_and_loss + self.height_to_net_unrealized_pnl .as_mut() .unwrap() .compute_subtract( @@ -2760,7 +2757,7 @@ impl Vecs { exit, )?; - self.indexes_to_net_unrealized_profit_and_loss + self.indexes_to_net_unrealized_pnl .as_mut() .unwrap() .compute_all( @@ -2778,7 +2775,7 @@ impl Vecs { Ok(()) }, )?; - self.height_to_unrealized_profit_relative_to_market_cap + self.height_to_unrealized_profit_rel_to_market_cap .as_mut() .unwrap() .compute_percentage( @@ -2787,7 +2784,7 @@ impl Vecs { height_to_market_cap, exit, )?; - self.height_to_unrealized_loss_relative_to_market_cap + self.height_to_unrealized_loss_rel_to_market_cap .as_mut() .unwrap() .compute_percentage( @@ -2796,27 +2793,25 @@ impl Vecs { height_to_market_cap, exit, )?; - self.height_to_negative_unrealized_loss_relative_to_market_cap + self.height_to_neg_unrealized_loss_rel_to_market_cap .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - self.height_to_negative_unrealized_loss.as_ref().unwrap(), + self.height_to_neg_unrealized_loss.as_ref().unwrap(), height_to_market_cap, exit, )?; - self.height_to_net_unrealized_profit_and_loss_relative_to_market_cap + self.height_to_net_unrealized_pnl_rel_to_market_cap .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - self.height_to_net_unrealized_profit_and_loss - .as_ref() - .unwrap(), + self.height_to_net_unrealized_pnl.as_ref().unwrap(), height_to_market_cap, exit, )?; - self.indexes_to_unrealized_profit_relative_to_market_cap + self.indexes_to_unrealized_profit_rel_to_market_cap .as_mut() .unwrap() .compute_all( @@ -2834,7 +2829,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_unrealized_loss_relative_to_market_cap + self.indexes_to_unrealized_loss_rel_to_market_cap .as_mut() .unwrap() .compute_all( @@ -2852,7 +2847,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_negative_unrealized_loss_relative_to_market_cap + self.indexes_to_neg_unrealized_loss_rel_to_market_cap .as_mut() .unwrap() .compute_all( @@ -2863,7 +2858,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.dateindex, - self.indexes_to_negative_unrealized_loss + self.indexes_to_neg_unrealized_loss .as_ref() .unwrap() .dateindex @@ -2875,7 +2870,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_net_unrealized_profit_and_loss_relative_to_market_cap + self.indexes_to_net_unrealized_pnl_rel_to_market_cap .as_mut() .unwrap() .compute_all( @@ -2886,7 +2881,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.dateindex, - self.indexes_to_net_unrealized_profit_and_loss + self.indexes_to_net_unrealized_pnl .as_ref() .unwrap() .dateindex @@ -2900,10 +2895,10 @@ impl Vecs { )?; if self - .height_to_unrealized_profit_relative_to_own_market_cap + .height_to_unrealized_profit_rel_to_own_market_cap .is_some() { - self.height_to_unrealized_profit_relative_to_own_market_cap + self.height_to_unrealized_profit_rel_to_own_market_cap .as_mut() .unwrap() .compute_percentage( @@ -2912,7 +2907,7 @@ impl Vecs { self.height_to_supply_value.dollars.as_ref().unwrap(), exit, )?; - self.height_to_unrealized_loss_relative_to_own_market_cap + self.height_to_unrealized_loss_rel_to_own_market_cap .as_mut() .unwrap() .compute_percentage( @@ -2921,27 +2916,25 @@ impl Vecs { self.height_to_supply_value.dollars.as_ref().unwrap(), exit, )?; - self.height_to_negative_unrealized_loss_relative_to_own_market_cap + self.height_to_neg_unrealized_loss_rel_to_own_market_cap .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - self.height_to_negative_unrealized_loss.as_ref().unwrap(), + self.height_to_neg_unrealized_loss.as_ref().unwrap(), self.height_to_supply_value.dollars.as_ref().unwrap(), exit, )?; - self.height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap + self.height_to_net_unrealized_pnl_rel_to_own_market_cap .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - self.height_to_net_unrealized_profit_and_loss - .as_ref() - .unwrap(), + self.height_to_net_unrealized_pnl.as_ref().unwrap(), self.height_to_supply_value.dollars.as_ref().unwrap(), exit, )?; - self.indexes_to_unrealized_profit_relative_to_own_market_cap + self.indexes_to_unrealized_profit_rel_to_own_market_cap .as_mut() .unwrap() .compute_all( @@ -2965,7 +2958,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_unrealized_loss_relative_to_own_market_cap + self.indexes_to_unrealized_loss_rel_to_own_market_cap .as_mut() .unwrap() .compute_all( @@ -2989,7 +2982,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_negative_unrealized_loss_relative_to_own_market_cap + self.indexes_to_neg_unrealized_loss_rel_to_own_market_cap .as_mut() .unwrap() .compute_all( @@ -3000,7 +2993,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.dateindex, - self.indexes_to_negative_unrealized_loss + self.indexes_to_neg_unrealized_loss .as_ref() .unwrap() .dateindex @@ -3018,7 +3011,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap + self.indexes_to_net_unrealized_pnl_rel_to_own_market_cap .as_mut() .unwrap() .compute_all( @@ -3029,7 +3022,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.dateindex, - self.indexes_to_net_unrealized_profit_and_loss + self.indexes_to_net_unrealized_pnl .as_ref() .unwrap() .dateindex @@ -3050,48 +3043,46 @@ impl Vecs { } if self - .height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss + .height_to_unrealized_profit_rel_to_own_unrealized_total_pnl .is_some() { - self.height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss + self.height_to_unrealized_profit_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_percentage( starting_indexes.height, self.height_to_unrealized_profit.as_ref().unwrap(), - self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(), + self.height_to_unrealized_total_pnl.as_ref().unwrap(), exit, )?; - self.height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss + self.height_to_unrealized_loss_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_percentage( starting_indexes.height, self.height_to_unrealized_loss.as_ref().unwrap(), - self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(), + self.height_to_unrealized_total_pnl.as_ref().unwrap(), exit, )?; - self.height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss + self.height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - self.height_to_negative_unrealized_loss.as_ref().unwrap(), - self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(), + self.height_to_neg_unrealized_loss.as_ref().unwrap(), + self.height_to_unrealized_total_pnl.as_ref().unwrap(), exit, )?; - self.height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss + self.height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - self.height_to_net_unrealized_profit_and_loss - .as_ref() - .unwrap(), - self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(), + self.height_to_net_unrealized_pnl.as_ref().unwrap(), + self.height_to_unrealized_total_pnl.as_ref().unwrap(), exit, )?; - self.indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss + self.indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_all( @@ -3103,7 +3094,7 @@ impl Vecs { vec.compute_percentage( starting_indexes.dateindex, self.dateindex_to_unrealized_profit.as_ref().unwrap(), - self.indexes_to_unrealized_profit_plus_loss + self.indexes_to_unrealized_total_pnl .as_ref() .unwrap() .dateindex @@ -3114,7 +3105,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss + self.indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_all( @@ -3126,7 +3117,7 @@ impl Vecs { vec.compute_percentage( starting_indexes.dateindex, self.dateindex_to_unrealized_loss.as_ref().unwrap(), - self.indexes_to_unrealized_profit_plus_loss + self.indexes_to_unrealized_total_pnl .as_ref() .unwrap() .dateindex @@ -3137,7 +3128,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss + self.indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_all( @@ -3148,13 +3139,13 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.dateindex, - self.indexes_to_negative_unrealized_loss + self.indexes_to_neg_unrealized_loss .as_ref() .unwrap() .dateindex .as_ref() .unwrap(), - self.indexes_to_unrealized_profit_plus_loss + self.indexes_to_unrealized_total_pnl .as_ref() .unwrap() .dateindex @@ -3165,7 +3156,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss + self.indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl .as_mut() .unwrap() .compute_all( @@ -3176,13 +3167,13 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.dateindex, - self.indexes_to_net_unrealized_profit_and_loss + self.indexes_to_net_unrealized_pnl .as_ref() .unwrap() .dateindex .as_ref() .unwrap(), - self.indexes_to_unrealized_profit_plus_loss + self.indexes_to_unrealized_total_pnl .as_ref() .unwrap() .dateindex @@ -3195,7 +3186,7 @@ impl Vecs { )?; } - self.indexes_to_realized_profit_relative_to_realized_cap + self.indexes_to_realized_profit_rel_to_realized_cap .as_mut() .unwrap() .compute_all( @@ -3214,7 +3205,7 @@ impl Vecs { }, )?; - self.indexes_to_realized_loss_relative_to_realized_cap + self.indexes_to_realized_loss_rel_to_realized_cap .as_mut() .unwrap() .compute_all( @@ -3233,7 +3224,7 @@ impl Vecs { }, )?; - self.indexes_to_net_realized_profit_and_loss_relative_to_realized_cap + self.indexes_to_net_realized_pnl_rel_to_realized_cap .as_mut() .unwrap() .compute_all( @@ -3244,7 +3235,7 @@ impl Vecs { |vec, _, _, starting_indexes, exit| { vec.compute_percentage( starting_indexes.height, - self.indexes_to_net_realized_profit_and_loss + self.indexes_to_net_realized_pnl .as_ref() .unwrap() .height @@ -3257,14 +3248,14 @@ impl Vecs { }, )?; - self.height_to_supply_even_value + self.height_to_supply_breakeven_value .as_mut() .unwrap() .compute_rest( price, starting_indexes, exit, - Some(self.height_to_supply_even.as_ref().unwrap()), + Some(self.height_to_supply_breakeven.as_ref().unwrap()), )?; self.height_to_supply_in_loss_value .as_mut() @@ -3284,16 +3275,20 @@ impl Vecs { exit, Some(self.height_to_supply_in_profit.as_ref().unwrap()), )?; - self.height_to_supply_even_relative_to_own_supply + self.height_to_supply_breakeven_rel_to_own_supply .as_mut() .unwrap() .compute_percentage( starting_indexes.height, - &self.height_to_supply_even_value.as_ref().unwrap().bitcoin, + &self + .height_to_supply_breakeven_value + .as_ref() + .unwrap() + .bitcoin, &self.height_to_supply_value.bitcoin, exit, )?; - self.height_to_supply_in_loss_relative_to_own_supply + self.height_to_supply_in_loss_rel_to_own_supply .as_mut() .unwrap() .compute_percentage( @@ -3306,7 +3301,7 @@ impl Vecs { &self.height_to_supply_value.bitcoin, exit, )?; - self.height_to_supply_in_profit_relative_to_own_supply + self.height_to_supply_in_profit_rel_to_own_supply .as_mut() .unwrap() .compute_percentage( @@ -3319,7 +3314,7 @@ impl Vecs { &self.height_to_supply_value.bitcoin, exit, )?; - self.indexes_to_supply_even_relative_to_own_supply + self.indexes_to_supply_breakeven_rel_to_own_supply .as_mut() .unwrap() .compute_all( @@ -3330,7 +3325,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage( starting_indexes.dateindex, - self.indexes_to_supply_even + self.indexes_to_supply_breakeven .as_ref() .unwrap() .bitcoin @@ -3343,7 +3338,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_supply_in_loss_relative_to_own_supply + self.indexes_to_supply_in_loss_rel_to_own_supply .as_mut() .unwrap() .compute_all( @@ -3367,7 +3362,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_supply_in_profit_relative_to_own_supply + self.indexes_to_supply_in_profit_rel_to_own_supply .as_mut() .unwrap() .compute_all( @@ -3392,7 +3387,7 @@ impl Vecs { }, )?; - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change + self.indexes_to_net_realized_pnl_cumulative_30d_delta .as_mut() .unwrap() .compute_all( @@ -3403,7 +3398,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_change( starting_indexes.dateindex, - self.indexes_to_net_realized_profit_and_loss + self.indexes_to_net_realized_pnl .as_ref() .unwrap() .dateindex @@ -3415,8 +3410,8 @@ impl Vecs { }, )?; - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap. - as_mut() + self.indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap + .as_mut() .unwrap() .compute_all( indexer, @@ -3426,7 +3421,12 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage( starting_indexes.dateindex, - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change.as_ref().unwrap().dateindex.as_ref().unwrap(), + self.indexes_to_net_realized_pnl_cumulative_30d_delta + .as_ref() + .unwrap() + .dateindex + .as_ref() + .unwrap(), *dateindex_to_realized_cap.as_ref().unwrap(), exit, )?; @@ -3434,8 +3434,8 @@ impl Vecs { }, )?; - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap. - as_mut() + self.indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_market_cap + .as_mut() .unwrap() .compute_all( indexer, @@ -3445,7 +3445,12 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage( starting_indexes.dateindex, - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change.as_ref().unwrap().dateindex.as_ref().unwrap(), + self.indexes_to_net_realized_pnl_cumulative_30d_delta + .as_ref() + .unwrap() + .dateindex + .as_ref() + .unwrap(), dateindex_to_market_cap, exit, )?; @@ -3453,17 +3458,21 @@ impl Vecs { }, )?; - if let Some(height_to_supply_even_relative_to_circulating_supply) = self - .height_to_supply_even_relative_to_circulating_supply + if let Some(height_to_supply_breakeven_rel_to_circulating_supply) = self + .height_to_supply_breakeven_rel_to_circulating_supply .as_mut() { - height_to_supply_even_relative_to_circulating_supply.compute_percentage( + height_to_supply_breakeven_rel_to_circulating_supply.compute_percentage( starting_indexes.height, - &self.height_to_supply_even_value.as_ref().unwrap().bitcoin, + &self + .height_to_supply_breakeven_value + .as_ref() + .unwrap() + .bitcoin, height_to_supply, exit, )?; - self.height_to_supply_in_loss_relative_to_circulating_supply + self.height_to_supply_in_loss_rel_to_circulating_supply .as_mut() .unwrap() .compute_percentage( @@ -3476,7 +3485,7 @@ impl Vecs { height_to_supply, exit, )?; - self.height_to_supply_in_profit_relative_to_circulating_supply + self.height_to_supply_in_profit_rel_to_circulating_supply .as_mut() .unwrap() .compute_percentage( @@ -3489,7 +3498,7 @@ impl Vecs { height_to_supply, exit, )?; - self.indexes_to_supply_even_relative_to_circulating_supply + self.indexes_to_supply_breakeven_rel_to_circulating_supply .as_mut() .unwrap() .compute_all( @@ -3500,7 +3509,7 @@ impl Vecs { |v, _, _, starting_indexes, exit| { v.compute_percentage( starting_indexes.dateindex, - self.indexes_to_supply_even + self.indexes_to_supply_breakeven .as_ref() .unwrap() .bitcoin @@ -3513,7 +3522,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_supply_in_loss_relative_to_circulating_supply + self.indexes_to_supply_in_loss_rel_to_circulating_supply .as_mut() .unwrap() .compute_all( @@ -3537,7 +3546,7 @@ impl Vecs { Ok(()) }, )?; - self.indexes_to_supply_in_profit_relative_to_circulating_supply + self.indexes_to_supply_in_profit_rel_to_circulating_supply .as_mut() .unwrap() .compute_all( @@ -3584,7 +3593,7 @@ impl Vecs { Some(self.height_to_adjusted_value_destroyed.as_ref().unwrap()), )?; - self.dateindex_to_adjusted_spent_output_profit_ratio + self.dateindex_to_adjusted_sopr .as_mut() .unwrap() .compute_divide( @@ -3602,30 +3611,46 @@ impl Vecs { exit, )?; - self.dateindex_to_adjusted_spent_output_profit_ratio_7d_ema + self.dateindex_to_adjusted_sopr_7d_ema .as_mut() .unwrap() .compute_ema( starting_indexes.dateindex, - self.dateindex_to_adjusted_spent_output_profit_ratio - .as_ref() - .unwrap(), + self.dateindex_to_adjusted_sopr.as_ref().unwrap(), 7, exit, )?; - self.dateindex_to_adjusted_spent_output_profit_ratio_30d_ema + self.dateindex_to_adjusted_sopr_30d_ema .as_mut() .unwrap() .compute_ema( starting_indexes.dateindex, - self.dateindex_to_adjusted_spent_output_profit_ratio - .as_ref() - .unwrap(), + self.dateindex_to_adjusted_sopr.as_ref().unwrap(), 30, exit, )?; } + + if let Some(indexes_to_realized_cap_rel_to_own_market_cap) = + self.indexes_to_realized_cap_rel_to_own_market_cap.as_mut() + { + indexes_to_realized_cap_rel_to_own_market_cap.compute_all( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_percentage( + starting_indexes.height, + self.height_to_realized_cap.as_ref().unwrap(), + self.height_to_supply_value.dollars.as_ref().unwrap(), + exit, + )?; + Ok(()) + }, + )?; + } } Ok(()) @@ -3643,7 +3668,7 @@ impl Vecs { .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), self.height_to_supply_value.vecs(), - self.height_to_halved_supply_value.vecs(), + self.height_to_supply_half_value.vecs(), self.indexes_to_supply.vecs(), self.indexes_to_utxo_count.vecs(), self.indexes_to_realized_cap @@ -3670,7 +3695,7 @@ impl Vecs { self.indexes_to_realized_loss .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_negative_realized_loss + self.indexes_to_neg_realized_loss .as_ref() .map_or(vec![], |v| v.vecs()), self.height_to_value_created @@ -3688,22 +3713,22 @@ impl Vecs { self.height_to_value_destroyed .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), - self.dateindex_to_spent_output_profit_ratio + self.dateindex_to_sopr .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), - self.dateindex_to_spent_output_profit_ratio_7d_ema + self.dateindex_to_sopr_7d_ema .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), - self.dateindex_to_spent_output_profit_ratio_30d_ema + self.dateindex_to_sopr_30d_ema .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), - self.dateindex_to_adjusted_spent_output_profit_ratio + self.dateindex_to_adjusted_sopr .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), - self.dateindex_to_adjusted_spent_output_profit_ratio_7d_ema + self.dateindex_to_adjusted_sopr_7d_ema .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), - self.dateindex_to_adjusted_spent_output_profit_ratio_30d_ema + self.dateindex_to_adjusted_sopr_30d_ema .as_ref() .map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]), self.indexes_to_value_destroyed @@ -3715,10 +3740,10 @@ impl Vecs { self.indexes_to_adjusted_value_destroyed .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_realized_cap_30d_change + self.indexes_to_realized_cap_30d_delta .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_realized_profit_and_loss + self.indexes_to_net_realized_pnl .as_ref() .map_or(vec![], |v| v.vecs()), self.dateindex_to_sell_side_risk_ratio @@ -3736,7 +3761,7 @@ impl Vecs { self.height_to_supply_in_loss .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_supply_even + self.height_to_supply_breakeven .as_ref() .map_or(vec![], |v| vec![v]), self.height_to_unrealized_profit @@ -3751,7 +3776,7 @@ impl Vecs { self.dateindex_to_supply_in_loss .as_ref() .map_or(vec![], |v| vec![v]), - self.dateindex_to_supply_even + self.dateindex_to_supply_breakeven .as_ref() .map_or(vec![], |v| vec![v]), self.dateindex_to_unrealized_profit @@ -3772,7 +3797,7 @@ impl Vecs { self.indexes_to_supply_in_loss .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_supply_even + self.indexes_to_supply_breakeven .as_ref() .map_or(vec![], |v| v.vecs()), self.indexes_to_unrealized_profit @@ -3781,10 +3806,10 @@ impl Vecs { self.indexes_to_unrealized_loss .as_ref() .map_or(vec![], |v| v.vecs()), - self.height_to_unrealized_profit_plus_loss + self.height_to_unrealized_total_pnl .as_ref() .map_or(vec![], |v| vec![v]), - self.indexes_to_unrealized_profit_plus_loss + self.indexes_to_unrealized_total_pnl .as_ref() .map_or(vec![], |v| v.vecs()), self.indexes_to_min_price_paid @@ -3793,85 +3818,101 @@ impl Vecs { self.indexes_to_max_price_paid .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_halved_supply.vecs(), - self.height_to_unrealized_profit_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| vec![v]), - self.height_to_unrealized_loss_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| vec![v]), - self.height_to_negative_unrealized_loss_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| vec![v]), - self.height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| vec![v]), - self.indexes_to_unrealized_profit_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_unrealized_loss_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_negative_unrealized_loss_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap.as_ref() - .map_or(vec![], |v| v.vecs()), - self.height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| vec![v]), - self.height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| vec![v]), - self.height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| vec![v]), - self.height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| vec![v]), - self.indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss.as_ref() - .map_or(vec![], |v| v.vecs()), - self.height_to_negative_unrealized_loss + self.indexes_to_supply_half.vecs(), + self.height_to_unrealized_profit_rel_to_own_market_cap .as_ref() .map_or(vec![], |v| vec![v]), - self.indexes_to_negative_unrealized_loss - .as_ref() - .map_or(vec![], |v| v.vecs()), - self.height_to_net_unrealized_profit_and_loss + self.height_to_unrealized_loss_rel_to_own_market_cap .as_ref() .map_or(vec![], |v| vec![v]), - self.indexes_to_net_unrealized_profit_and_loss - .as_ref() - .map_or(vec![], |v| v.vecs()), - self.height_to_unrealized_profit_relative_to_market_cap + self.height_to_neg_unrealized_loss_rel_to_own_market_cap .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_unrealized_loss_relative_to_market_cap + self.height_to_net_unrealized_pnl_rel_to_own_market_cap .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_negative_unrealized_loss_relative_to_market_cap + self.indexes_to_unrealized_profit_rel_to_own_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_unrealized_loss_rel_to_own_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_neg_unrealized_loss_rel_to_own_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_net_unrealized_pnl_rel_to_own_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.height_to_unrealized_profit_rel_to_own_unrealized_total_pnl .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_net_unrealized_profit_and_loss_relative_to_market_cap + self.height_to_unrealized_loss_rel_to_own_unrealized_total_pnl .as_ref() .map_or(vec![], |v| vec![v]), - self.indexes_to_unrealized_profit_relative_to_market_cap + self.height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl + .as_ref() + .map_or(vec![], |v| vec![v]), + self.height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl + .as_ref() + .map_or(vec![], |v| vec![v]), + self.indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_unrealized_loss_relative_to_market_cap + self.indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_negative_unrealized_loss_relative_to_market_cap + self.indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_unrealized_profit_and_loss_relative_to_market_cap + self.indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_realized_profit_relative_to_realized_cap + self.height_to_neg_unrealized_loss + .as_ref() + .map_or(vec![], |v| vec![v]), + self.indexes_to_neg_unrealized_loss .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_realized_loss_relative_to_realized_cap + self.height_to_net_unrealized_pnl + .as_ref() + .map_or(vec![], |v| vec![v]), + self.indexes_to_net_unrealized_pnl .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_realized_profit_and_loss_relative_to_realized_cap + self.height_to_unrealized_profit_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| vec![v]), + self.height_to_unrealized_loss_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| vec![v]), + self.height_to_neg_unrealized_loss_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| vec![v]), + self.height_to_net_unrealized_pnl_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| vec![v]), + self.indexes_to_unrealized_profit_rel_to_market_cap .as_ref() .map_or(vec![], |v| v.vecs()), - self.height_to_supply_even_value + self.indexes_to_unrealized_loss_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_neg_unrealized_loss_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_net_unrealized_pnl_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_realized_profit_rel_to_realized_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_realized_loss_rel_to_realized_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_net_realized_pnl_rel_to_realized_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.height_to_supply_breakeven_value .as_ref() .map_or(vec![], |v| v.vecs()), self.height_to_supply_in_loss_value @@ -3880,53 +3921,59 @@ impl Vecs { self.height_to_supply_in_profit_value .as_ref() .map_or(vec![], |v| v.vecs()), - self.height_to_supply_even_relative_to_own_supply + self.height_to_supply_breakeven_rel_to_own_supply .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_supply_in_loss_relative_to_own_supply + self.height_to_supply_in_loss_rel_to_own_supply .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_supply_in_profit_relative_to_own_supply + self.height_to_supply_in_profit_rel_to_own_supply .as_ref() .map_or(vec![], |v| vec![v]), - self.indexes_to_supply_even_relative_to_own_supply + self.indexes_to_supply_breakeven_rel_to_own_supply .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_supply_in_loss_relative_to_own_supply + self.indexes_to_supply_in_loss_rel_to_own_supply .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_supply_in_profit_relative_to_own_supply + self.indexes_to_supply_in_profit_rel_to_own_supply .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_supply_relative_to_circulating_supply + self.indexes_to_supply_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| v.vecs()), - self.height_to_supply_even_relative_to_circulating_supply + self.height_to_supply_breakeven_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_supply_in_loss_relative_to_circulating_supply + self.height_to_supply_in_loss_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| vec![v]), - self.height_to_supply_in_profit_relative_to_circulating_supply + self.height_to_supply_in_profit_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| vec![v]), - self.indexes_to_supply_even_relative_to_circulating_supply + self.indexes_to_supply_breakeven_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_supply_in_loss_relative_to_circulating_supply + self.indexes_to_supply_in_loss_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| v.vecs()), - self.indexes_to_supply_in_profit_relative_to_circulating_supply + self.indexes_to_supply_in_profit_rel_to_circulating_supply .as_ref() .map_or(vec![], |v| v.vecs()), self.indexes_to_coinblocks_destroyed.vecs(), self.indexes_to_coindays_destroyed.vecs(), - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap.as_ref() - .map_or(vec![], |v| v.vecs()), - self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap.as_ref() - .map_or(vec![], |v| v.vecs()), + self.indexes_to_net_realized_pnl_cumulative_30d_delta + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_net_realized_pnl_cumulative_30d_delta_rel_to_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), + self.indexes_to_realized_cap_rel_to_own_market_cap + .as_ref() + .map_or(vec![], |v| v.vecs()), ] .into_iter() .flatten() diff --git a/crates/brk_computer/src/stateful/mod.rs b/crates/brk_computer/src/stateful/mod.rs index 9fe417b77..bca4b221e 100644 --- a/crates/brk_computer/src/stateful/mod.rs +++ b/crates/brk_computer/src/stateful/mod.rs @@ -73,20 +73,24 @@ pub struct Vecs { pub height_to_unspendable_supply: EagerVec, pub height_to_opreturn_supply: EagerVec, - pub addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount, - pub addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount, + pub addresstype_to_height_to_addr_count: AddressTypeToHeightToAddressCount, + pub addresstype_to_height_to_empty_addr_count: AddressTypeToHeightToAddressCount, // --- // Computed // --- - pub addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount, - pub addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount, + pub addresstype_to_indexes_to_addr_count: AddressTypeToIndexesToAddressCount, + pub addresstype_to_indexes_to_empty_addr_count: AddressTypeToIndexesToAddressCount, pub indexes_to_unspendable_supply: ComputedValueVecsFromHeight, pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight, - pub indexes_to_address_count: ComputedVecsFromHeight, - pub indexes_to_empty_address_count: ComputedVecsFromHeight, + pub indexes_to_addr_count: ComputedVecsFromHeight, + pub indexes_to_empty_addr_count: ComputedVecsFromHeight, pub height_to_market_cap: Option>, pub indexes_to_market_cap: Option>, + pub loadedaddressindex_to_loadedaddressindex: + LazyVecFrom1, + pub emptyaddressindex_to_emptyaddressindex: + LazyVecFrom1, } const SAVED_STAMPED_CHANGES: u16 = 10; @@ -111,7 +115,28 @@ impl Vecs { let utxo_cohorts = utxo_cohorts::Vecs::forced_import(&db, version, format, indexes, price, &states_path)?; - Ok(Self { + let loadedaddressindex_to_loadedaddressdata = RawVec::forced_import_with( + ImportOptions::new(&db, "loadedaddressdata", version + VERSION + Version::ZERO) + .with_saved_stamped_changes(SAVED_STAMPED_CHANGES), + )?; + let emptyaddressindex_to_emptyaddressdata = RawVec::forced_import_with( + ImportOptions::new(&db, "emptyaddressdata", version + VERSION + Version::ZERO) + .with_saved_stamped_changes(SAVED_STAMPED_CHANGES), + )?; + let loadedaddressindex_to_loadedaddressindex = LazyVecFrom1::init( + "loadedaddressindex", + version + VERSION + Version::ZERO, + loadedaddressindex_to_loadedaddressdata.boxed_clone(), + |index, _| Some(index), + ); + let emptyaddressindex_to_emptyaddressindex = LazyVecFrom1::init( + "emptyaddressindex", + version + VERSION + Version::ZERO, + emptyaddressindex_to_emptyaddressdata.boxed_clone(), + |index, _| Some(index), + ); + + let this = Self { chain_state: RawVec::forced_import_with( ImportOptions::new(&db, "chain", version + VERSION + Version::ZERO) .with_saved_stamped_changes(SAVED_STAMPED_CHANGES), @@ -145,17 +170,17 @@ impl Vecs { compute_dollars, indexes, )?, - indexes_to_address_count: ComputedVecsFromHeight::forced_import( + indexes_to_addr_count: ComputedVecsFromHeight::forced_import( &db, - "address_count", + "addr_count", Source::Compute, version + VERSION + Version::ZERO, indexes, VecBuilderOptions::default().add_last(), )?, - indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import( + indexes_to_empty_addr_count: ComputedVecsFromHeight::forced_import( &db, - "empty_address_count", + "empty_addr_count", Source::Compute, version + VERSION + Version::ZERO, indexes, @@ -192,99 +217,99 @@ impl Vecs { ) .unwrap() }), - addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from( + addresstype_to_height_to_addr_count: AddressTypeToHeightToAddressCount::from( ByAddressType { p2pk65: EagerVec::forced_import_compressed( &db, - "p2pk65_address_count", + "p2pk65_addr_count", version + VERSION + Version::ZERO, )?, p2pk33: EagerVec::forced_import_compressed( &db, - "p2pk33_address_count", + "p2pk33_addr_count", version + VERSION + Version::ZERO, )?, p2pkh: EagerVec::forced_import_compressed( &db, - "p2pkh_address_count", + "p2pkh_addr_count", version + VERSION + Version::ZERO, )?, p2sh: EagerVec::forced_import_compressed( &db, - "p2sh_address_count", + "p2sh_addr_count", version + VERSION + Version::ZERO, )?, p2wpkh: EagerVec::forced_import_compressed( &db, - "p2wpkh_address_count", + "p2wpkh_addr_count", version + VERSION + Version::ZERO, )?, p2wsh: EagerVec::forced_import_compressed( &db, - "p2wsh_address_count", + "p2wsh_addr_count", version + VERSION + Version::ZERO, )?, p2tr: EagerVec::forced_import_compressed( &db, - "p2tr_address_count", + "p2tr_addr_count", version + VERSION + Version::ZERO, )?, p2a: EagerVec::forced_import_compressed( &db, - "p2a_address_count", + "p2a_addr_count", version + VERSION + Version::ZERO, )?, }, ), - addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount::from( + addresstype_to_height_to_empty_addr_count: AddressTypeToHeightToAddressCount::from( ByAddressType { p2pk65: EagerVec::forced_import_compressed( &db, - "p2pk65_empty_address_count", + "p2pk65_empty_addr_count", version + VERSION + Version::ZERO, )?, p2pk33: EagerVec::forced_import_compressed( &db, - "p2pk33_empty_address_count", + "p2pk33_empty_addr_count", version + VERSION + Version::ZERO, )?, p2pkh: EagerVec::forced_import_compressed( &db, - "p2pkh_empty_address_count", + "p2pkh_empty_addr_count", version + VERSION + Version::ZERO, )?, p2sh: EagerVec::forced_import_compressed( &db, - "p2sh_empty_address_count", + "p2sh_empty_addr_count", version + VERSION + Version::ZERO, )?, p2wpkh: EagerVec::forced_import_compressed( &db, - "p2wpkh_empty_address_count", + "p2wpkh_empty_addr_count", version + VERSION + Version::ZERO, )?, p2wsh: EagerVec::forced_import_compressed( &db, - "p2wsh_empty_address_count", + "p2wsh_empty_addr_count", version + VERSION + Version::ZERO, )?, p2tr: EagerVec::forced_import_compressed( &db, - "p2tr_empty_address_count", + "p2tr_empty_addr_count", version + VERSION + Version::ZERO, )?, p2a: EagerVec::forced_import_compressed( &db, - "p2a_empty_address_count", + "p2a_empty_addr_count", version + VERSION + Version::ZERO, )?, }, ), - addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount::from( + addresstype_to_indexes_to_addr_count: AddressTypeToIndexesToAddressCount::from( ByAddressType { p2pk65: ComputedVecsFromHeight::forced_import( &db, - "p2pk65_address_count", + "p2pk65_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -292,7 +317,7 @@ impl Vecs { )?, p2pk33: ComputedVecsFromHeight::forced_import( &db, - "p2pk33_address_count", + "p2pk33_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -300,7 +325,7 @@ impl Vecs { )?, p2pkh: ComputedVecsFromHeight::forced_import( &db, - "p2pkh_address_count", + "p2pkh_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -308,7 +333,7 @@ impl Vecs { )?, p2sh: ComputedVecsFromHeight::forced_import( &db, - "p2sh_address_count", + "p2sh_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -316,7 +341,7 @@ impl Vecs { )?, p2wpkh: ComputedVecsFromHeight::forced_import( &db, - "p2wpkh_address_count", + "p2wpkh_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -324,7 +349,7 @@ impl Vecs { )?, p2wsh: ComputedVecsFromHeight::forced_import( &db, - "p2wsh_address_count", + "p2wsh_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -332,7 +357,7 @@ impl Vecs { )?, p2tr: ComputedVecsFromHeight::forced_import( &db, - "p2tr_address_count", + "p2tr_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -340,7 +365,7 @@ impl Vecs { )?, p2a: ComputedVecsFromHeight::forced_import( &db, - "p2a_address_count", + "p2a_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -348,11 +373,11 @@ impl Vecs { )?, }, ), - addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount::from( + addresstype_to_indexes_to_empty_addr_count: AddressTypeToIndexesToAddressCount::from( ByAddressType { p2pk65: ComputedVecsFromHeight::forced_import( &db, - "p2pk65_empty_address_count", + "p2pk65_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -360,7 +385,7 @@ impl Vecs { )?, p2pk33: ComputedVecsFromHeight::forced_import( &db, - "p2pk33_empty_address_count", + "p2pk33_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -368,7 +393,7 @@ impl Vecs { )?, p2pkh: ComputedVecsFromHeight::forced_import( &db, - "p2pkh_empty_address_count", + "p2pkh_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -376,7 +401,7 @@ impl Vecs { )?, p2sh: ComputedVecsFromHeight::forced_import( &db, - "p2sh_empty_address_count", + "p2sh_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -384,7 +409,7 @@ impl Vecs { )?, p2wpkh: ComputedVecsFromHeight::forced_import( &db, - "p2wpkh_empty_address_count", + "p2wpkh_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -392,7 +417,7 @@ impl Vecs { )?, p2wsh: ComputedVecsFromHeight::forced_import( &db, - "p2wsh_empty_address_count", + "p2wsh_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -400,7 +425,7 @@ impl Vecs { )?, p2tr: ComputedVecsFromHeight::forced_import( &db, - "p2tr_empty_address_count", + "p2tr_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -408,7 +433,7 @@ impl Vecs { )?, p2a: ComputedVecsFromHeight::forced_import( &db, - "p2a_empty_address_count", + "p2a_empty_addr_count", Source::None, version + VERSION + Version::ZERO, indexes, @@ -459,17 +484,22 @@ impl Vecs { .with_saved_stamped_changes(SAVED_STAMPED_CHANGES), )?, - loadedaddressindex_to_loadedaddressdata: RawVec::forced_import_with( - ImportOptions::new(&db, "loadedaddressdata", version + VERSION + Version::ZERO) - .with_saved_stamped_changes(SAVED_STAMPED_CHANGES), - )?, - emptyaddressindex_to_emptyaddressdata: RawVec::forced_import_with( - ImportOptions::new(&db, "emptyaddressdata", version + VERSION + Version::ZERO) - .with_saved_stamped_changes(SAVED_STAMPED_CHANGES), - )?, + loadedaddressindex_to_loadedaddressdata, + emptyaddressindex_to_emptyaddressdata, + loadedaddressindex_to_loadedaddressindex, + emptyaddressindex_to_emptyaddressindex, db, - }) + }; + + this.db.retain_regions( + this.vecs() + .into_iter() + .flat_map(|v| v.region_names()) + .collect(), + )?; + + Ok(this) } #[allow(clippy::too_many_arguments)] @@ -524,17 +554,17 @@ impl Vecs { .height .as_ref() .unwrap(); - let height_to_close = price + let height_to_price_close = price .as_ref() - .map(|price| &price.chainindexes_to_close.height); - let dateindex_to_close = price + .map(|price| &price.chainindexes_to_price_close.height); + let dateindex_to_price_close = price .as_ref() - .map(|price| price.timeindexes_to_close.dateindex.as_ref().unwrap()); + .map(|price| price.timeindexes_to_price_close.dateindex.as_ref().unwrap()); let height_to_date_fixed = &indexes.height_to_date_fixed; let dateindex_to_first_height = &indexes.dateindex_to_first_height; let dateindex_to_height_count = &indexes.dateindex_to_height_count; - let mut height_to_close_iter = height_to_close.as_ref().map(|v| v.into_iter()); + let mut height_to_price_close_iter = height_to_price_close.as_ref().map(|v| v.into_iter()); let mut height_to_timestamp_fixed_iter = height_to_timestamp_fixed.into_iter(); let base_version = Version::ZERO @@ -558,10 +588,10 @@ impl Vecs { + outputindex_to_outputtype.version() + outputindex_to_typeindex.version() + height_to_unclaimed_rewards.version() - + height_to_close + + height_to_price_close .as_ref() .map_or(Version::ZERO, |v| v.version()) - + dateindex_to_close + + dateindex_to_price_close .as_ref() .map_or(Version::ZERO, |v| v.version()) + height_to_date_fixed.version() @@ -657,12 +687,14 @@ impl Vecs { .rollback_before(starting_height.into())?, ] .into_iter() - .enumerate() - .map(|(i, s)| { - let h = Height::from(s).incremented(); - dbg!((i, s, h)); - h - }) + // .enumerate() + // .map(|(i, s)| { + // let h = Height::from(s).incremented(); + // // dbg!((i, s, h)); + // h + // }) + .map(Height::from) + .map(Height::incremented) .collect::>(); if set.len() == 1 { @@ -709,7 +741,7 @@ impl Vecs { .map(|(height, supply)| { let height = Height::from(height); let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height); - let price = height_to_close_iter + let price = height_to_price_close_iter .as_mut() .map(|i| *i.unwrap_get_inner(height)); BlockState { @@ -780,13 +812,14 @@ impl Vecs { let mut height_to_output_count_iter = height_to_output_count.into_iter(); let mut height_to_input_count_iter = height_to_input_count.into_iter(); let mut height_to_unclaimed_rewards_iter = height_to_unclaimed_rewards.into_iter(); - let mut dateindex_to_close_iter = dateindex_to_close.as_ref().map(|v| v.into_iter()); + let mut dateindex_to_price_close_iter = + dateindex_to_price_close.as_ref().map(|v| v.into_iter()); let mut height_to_date_fixed_iter = height_to_date_fixed.into_iter(); let mut dateindex_to_first_height_iter = dateindex_to_first_height.into_iter(); let mut dateindex_to_height_count_iter = dateindex_to_height_count.into_iter(); - let height_to_close_vec = - height_to_close.map(|height_to_close| height_to_close.collect().unwrap()); + let height_to_price_close_vec = height_to_price_close + .map(|height_to_price_close| height_to_price_close.collect().unwrap()); let height_to_timestamp_fixed_vec = height_to_timestamp_fixed.collect().unwrap(); let outputindex_range_to_height = RangeMap::from(height_to_first_outputindex); @@ -805,12 +838,12 @@ impl Vecs { } else { Sats::ZERO }; - let mut addresstype_to_address_count = AddressTypeToAddressCount::from(( - &self.addresstype_to_height_to_address_count, + let mut addresstype_to_addr_count = AddressTypeToAddressCount::from(( + &self.addresstype_to_height_to_addr_count, starting_height, )); - let mut addresstype_to_empty_address_count = AddressTypeToAddressCount::from(( - &self.addresstype_to_height_to_empty_address_count, + let mut addresstype_to_empty_addr_count = AddressTypeToAddressCount::from(( + &self.addresstype_to_height_to_empty_addr_count, starting_height, )); @@ -855,7 +888,7 @@ impl Vecs { .for_each(|(_, v)| v.state.as_mut().unwrap().reset_single_iteration_values()); let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height); - let price = height_to_close_iter + let price = height_to_price_close_iter .as_mut() .map(|i| *i.unwrap_get_inner(height)); let first_outputindex = height_to_first_outputindex_iter @@ -1123,8 +1156,8 @@ impl Vecs { &mut addresstype_to_typeindex_to_loadedaddressdata, &mut addresstype_to_typeindex_to_emptyaddressdata, price, - &mut addresstype_to_address_count, - &mut addresstype_to_empty_address_count, + &mut addresstype_to_addr_count, + &mut addresstype_to_empty_addr_count, &mut stored_or_new_addresstype_to_typeindex_to_addressdatawithsource, ); @@ -1134,9 +1167,9 @@ impl Vecs { &mut addresstype_to_typeindex_to_loadedaddressdata, &mut addresstype_to_typeindex_to_emptyaddressdata, price, - &mut addresstype_to_address_count, - &mut addresstype_to_empty_address_count, - height_to_close_vec.as_ref(), + &mut addresstype_to_addr_count, + &mut addresstype_to_empty_addr_count, + height_to_price_close_vec.as_ref(), &height_to_timestamp_fixed_vec, height, timestamp, @@ -1195,14 +1228,14 @@ impl Vecs { self.height_to_opreturn_supply .forced_push_at(height, opreturn_supply, exit)?; - self.addresstype_to_height_to_address_count.forced_push_at( + self.addresstype_to_height_to_addr_count.forced_push_at( height, - &addresstype_to_address_count, + &addresstype_to_addr_count, exit, )?; - self.addresstype_to_height_to_empty_address_count - .forced_push_at(height, &addresstype_to_empty_address_count, exit)?; + self.addresstype_to_height_to_empty_addr_count + .forced_push_at(height, &addresstype_to_empty_addr_count, exit)?; let date = height_to_date_fixed_iter.unwrap_get_inner(height); let dateindex = DateIndex::try_from(date).unwrap(); @@ -1213,7 +1246,7 @@ impl Vecs { let is_date_last_height = date_first_height + Height::from(date_height_count).decremented().unwrap() == height; - let date_price = dateindex_to_close_iter + let date_price = dateindex_to_price_close_iter .as_mut() .map(|v| is_date_last_height.then(|| *v.unwrap_get_inner(dateindex))); @@ -1276,7 +1309,7 @@ impl Vecs { info!("Computing rest part 1..."); - self.indexes_to_address_count.compute_all( + self.indexes_to_addr_count.compute_all( indexer, indexes, starting_indexes, @@ -1285,7 +1318,7 @@ impl Vecs { v.compute_sum_of_others( starting_indexes.height, &self - .addresstype_to_height_to_address_count + .addresstype_to_height_to_addr_count .as_typed_vec() .into_iter() .map(|(_, v)| v) @@ -1296,7 +1329,7 @@ impl Vecs { }, )?; - self.indexes_to_empty_address_count.compute_all( + self.indexes_to_empty_addr_count.compute_all( indexer, indexes, starting_indexes, @@ -1305,7 +1338,7 @@ impl Vecs { v.compute_sum_of_others( starting_indexes.height, &self - .addresstype_to_height_to_empty_address_count + .addresstype_to_height_to_empty_addr_count .as_typed_vec() .into_iter() .map(|(_, v)| v) @@ -1333,18 +1366,18 @@ impl Vecs { Some(&self.height_to_opreturn_supply), )?; - self.addresstype_to_indexes_to_address_count.compute( + self.addresstype_to_indexes_to_addr_count.compute( indexes, starting_indexes, exit, - &self.addresstype_to_height_to_address_count, + &self.addresstype_to_height_to_addr_count, )?; - self.addresstype_to_indexes_to_empty_address_count.compute( + self.addresstype_to_indexes_to_empty_addr_count.compute( indexes, starting_indexes, exit, - &self.addresstype_to_height_to_empty_address_count, + &self.addresstype_to_height_to_empty_addr_count, )?; self.utxo_cohorts @@ -1643,11 +1676,11 @@ impl Vecs { .try_for_each(|(_, v)| v.safe_flush_stateful_vecs(height, exit))?; self.height_to_unspendable_supply.safe_flush(exit)?; self.height_to_opreturn_supply.safe_flush(exit)?; - self.addresstype_to_height_to_address_count + self.addresstype_to_height_to_addr_count .as_mut_vec() .into_iter() .try_for_each(|v| v.safe_flush(exit))?; - self.addresstype_to_height_to_empty_address_count + self.addresstype_to_height_to_empty_addr_count .as_mut_vec() .into_iter() .try_for_each(|v| v.safe_flush(exit))?; @@ -1845,19 +1878,19 @@ impl Vecs { .collect::>(), self.indexes_to_unspendable_supply.vecs(), self.indexes_to_opreturn_supply.vecs(), - self.indexes_to_address_count.vecs(), - self.indexes_to_empty_address_count.vecs(), - self.addresstype_to_indexes_to_address_count.vecs(), + self.indexes_to_addr_count.vecs(), + self.indexes_to_empty_addr_count.vecs(), + self.addresstype_to_indexes_to_addr_count.vecs(), self.indexes_to_market_cap .as_ref() .map_or(vec![], |v| v.vecs()), - self.addresstype_to_indexes_to_empty_address_count.vecs(), - self.addresstype_to_height_to_address_count + self.addresstype_to_indexes_to_empty_addr_count.vecs(), + self.addresstype_to_height_to_addr_count .as_typed_vec() .into_iter() .map(|(_, v)| v as &dyn AnyCollectableVec) .collect::>(), - self.addresstype_to_height_to_empty_address_count + self.addresstype_to_height_to_empty_addr_count .as_typed_vec() .into_iter() .map(|(_, v)| v as &dyn AnyCollectableVec) @@ -1868,6 +1901,19 @@ impl Vecs { vec![ &self.height_to_unspendable_supply, &self.height_to_opreturn_supply, + &self.chain_state, + &self.p2pk33addressindex_to_anyaddressindex, + &self.p2pk65addressindex_to_anyaddressindex, + &self.p2pkhaddressindex_to_anyaddressindex, + &self.p2shaddressindex_to_anyaddressindex, + &self.p2traddressindex_to_anyaddressindex, + &self.p2wpkhaddressindex_to_anyaddressindex, + &self.p2wshaddressindex_to_anyaddressindex, + &self.p2aaddressindex_to_anyaddressindex, + &self.loadedaddressindex_to_loadedaddressdata, + &self.emptyaddressindex_to_emptyaddressdata, + &self.loadedaddressindex_to_loadedaddressindex, + &self.emptyaddressindex_to_emptyaddressindex, ], ] .into_iter() @@ -1888,8 +1934,8 @@ impl AddressTypeToVec<(TypeIndex, Sats)> { WithAddressDataSource, >, price: Option, - addresstype_to_address_count: &mut ByAddressType, - addresstype_to_empty_address_count: &mut ByAddressType, + addresstype_to_addr_count: &mut ByAddressType, + addresstype_to_empty_addr_count: &mut ByAddressType, stored_or_new_addresstype_to_typeindex_to_addressdatawithsource: &mut AddressTypeToTypeIndexTree< WithAddressDataSource, >, @@ -1926,9 +1972,9 @@ impl AddressTypeToVec<(TypeIndex, Sats)> { }); if is_new || from_any_empty { - (*addresstype_to_address_count.get_mut(_type).unwrap()) += 1; + (*addresstype_to_addr_count.get_mut(_type).unwrap()) += 1; if from_any_empty { - (*addresstype_to_empty_address_count.get_mut(_type).unwrap()) -= 1; + (*addresstype_to_empty_addr_count.get_mut(_type).unwrap()) -= 1; } } @@ -1988,9 +2034,9 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> { WithAddressDataSource, >, price: Option, - addresstype_to_address_count: &mut ByAddressType, - addresstype_to_empty_address_count: &mut ByAddressType, - height_to_close_vec: Option<&Vec>>, + addresstype_to_addr_count: &mut ByAddressType, + addresstype_to_empty_addr_count: &mut ByAddressType, + height_to_price_close_vec: Option<&Vec>>, height_to_timestamp_fixed_vec: &[Timestamp], height: Height, timestamp: Timestamp, @@ -1999,7 +2045,7 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> { >, ) -> Result<()> { self.0.into_iter().try_for_each(|(prev_height, mut v)| { - let prev_price = height_to_close_vec + let prev_price = height_to_price_close_vec .as_ref() .map(|v| **v.get(prev_height.unwrap_to_usize()).unwrap()); @@ -2039,7 +2085,7 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> { let amount = prev_amount.checked_sub(value).unwrap(); - let will_be_empty = addressdata.outputs_len - 1 == 0; + let will_be_empty = addressdata.utxos - 1 == 0; if will_be_empty || vecs.amount_range.get_mut(amount).0.clone() @@ -2060,8 +2106,8 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> { unreachable!() } - (*addresstype_to_address_count.get_mut(_type).unwrap()) -= 1; - (*addresstype_to_empty_address_count.get_mut(_type).unwrap()) += 1; + (*addresstype_to_addr_count.get_mut(_type).unwrap()) -= 1; + (*addresstype_to_empty_addr_count.get_mut(_type).unwrap()) += 1; let addressdata = typeindex_to_loadedaddressdata.remove(&type_index).unwrap(); diff --git a/crates/brk_computer/src/stateful/utxo_cohort.rs b/crates/brk_computer/src/stateful/utxo_cohort.rs index ba91852a7..f49e879f5 100644 --- a/crates/brk_computer/src/stateful/utxo_cohort.rs +++ b/crates/brk_computer/src/stateful/utxo_cohort.rs @@ -33,7 +33,7 @@ impl Vecs { price: Option<&price::Vecs>, states_path: Option<&Path>, extended: bool, - compute_relative_to_all: bool, + compute_rel_to_all: bool, compute_adjusted: bool, ) -> Result { let compute_dollars = price.is_some(); @@ -57,7 +57,7 @@ impl Vecs { indexes, price, extended, - compute_relative_to_all, + compute_rel_to_all, compute_adjusted, )?, }) diff --git a/crates/brk_computer/src/stateful/utxo_cohorts.rs b/crates/brk_computer/src/stateful/utxo_cohorts.rs index a40760b0a..d6c2c1e43 100644 --- a/crates/brk_computer/src/stateful/utxo_cohorts.rs +++ b/crates/brk_computer/src/stateful/utxo_cohorts.rs @@ -49,7 +49,7 @@ impl Vecs { term: ByTerm { short: utxo_cohort::Vecs::forced_import( db, - Some("short_term_holders"), + Some("sth"), format, version + VERSION + Version::ZERO, indexes, @@ -61,7 +61,7 @@ impl Vecs { )?, long: utxo_cohort::Vecs::forced_import( db, - Some("long_term_holders"), + Some("lth"), format, version + VERSION + Version::ZERO, indexes, diff --git a/crates/brk_computer/src/states/cohorts/address.rs b/crates/brk_computer/src/states/cohorts/address.rs index 0af649f08..4c7bbcfcf 100644 --- a/crates/brk_computer/src/states/cohorts/address.rs +++ b/crates/brk_computer/src/states/cohorts/address.rs @@ -9,14 +9,14 @@ use super::CohortState; #[derive(Clone)] pub struct AddressCohortState { - pub address_count: u64, + pub addr_count: u64, pub inner: CohortState, } impl AddressCohortState { pub fn new(path: &Path, name: &str, compute_dollars: bool) -> Self { Self { - address_count: 0, + addr_count: 0, inner: CohortState::new(path, name, compute_dollars), } } @@ -44,14 +44,14 @@ impl AddressCohortState { let prev_realized_price = compute_price.then(|| addressdata.realized_price()); let prev_supply_state = SupplyState { - utxos: addressdata.outputs_len as u64, + utxos: addressdata.utxos as u64, value: addressdata.amount(), }; addressdata.send(value, prev_price)?; let supply_state = SupplyState { - utxos: addressdata.outputs_len as u64, + utxos: addressdata.utxos as u64, value: addressdata.amount(), }; @@ -79,14 +79,14 @@ impl AddressCohortState { let prev_realized_price = compute_price.then(|| address_data.realized_price()); let prev_supply_state = SupplyState { - utxos: address_data.outputs_len as u64, + utxos: address_data.utxos as u64, value: address_data.amount(), }; address_data.receive(value, price); let supply_state = SupplyState { - utxos: address_data.outputs_len as u64, + utxos: address_data.utxos as u64, value: address_data.amount(), }; @@ -99,7 +99,7 @@ impl AddressCohortState { } pub fn add(&mut self, addressdata: &LoadedAddressData) { - self.address_count += 1; + self.addr_count += 1; self.inner.increment_( &addressdata.into(), addressdata.realized_cap, @@ -108,7 +108,7 @@ impl AddressCohortState { } pub fn subtract(&mut self, addressdata: &LoadedAddressData) { - self.address_count = self.address_count.checked_sub(1).unwrap(); + self.addr_count = self.addr_count.checked_sub(1).unwrap(); self.inner.decrement_( &addressdata.into(), addressdata.realized_cap, diff --git a/crates/brk_computer/src/states/cohorts/common.rs b/crates/brk_computer/src/states/cohorts/common.rs index 243ffc0d1..74e90a103 100644 --- a/crates/brk_computer/src/states/cohorts/common.rs +++ b/crates/brk_computer/src/states/cohorts/common.rs @@ -283,7 +283,7 @@ impl CohortState { } } Ordering::Equal => { - state.supply_even += sats; + state.supply_breakeven += sats; } } }; diff --git a/crates/brk_computer/src/states/supply.rs b/crates/brk_computer/src/states/supply.rs index f94ed6fc0..cf85a7a5a 100644 --- a/crates/brk_computer/src/states/supply.rs +++ b/crates/brk_computer/src/states/supply.rs @@ -43,7 +43,7 @@ impl SubAssign<&SupplyState> for SupplyState { impl From<&LoadedAddressData> for SupplyState { fn from(value: &LoadedAddressData) -> Self { Self { - utxos: value.outputs_len as u64, + utxos: value.utxos as u64, value: value.amount(), } } diff --git a/crates/brk_computer/src/states/unrealized.rs b/crates/brk_computer/src/states/unrealized.rs index f514295fc..81b5950eb 100644 --- a/crates/brk_computer/src/states/unrealized.rs +++ b/crates/brk_computer/src/states/unrealized.rs @@ -3,7 +3,7 @@ use brk_structs::{Dollars, Sats}; #[derive(Debug, Default, Clone)] pub struct UnrealizedState { pub supply_in_profit: Sats, - pub supply_even: Sats, + pub supply_breakeven: Sats, pub supply_in_loss: Sats, pub unrealized_profit: Dollars, pub unrealized_loss: Dollars, @@ -12,7 +12,7 @@ pub struct UnrealizedState { impl UnrealizedState { pub const NAN: Self = Self { supply_in_profit: Sats::ZERO, - supply_even: Sats::ZERO, + supply_breakeven: Sats::ZERO, supply_in_loss: Sats::ZERO, unrealized_profit: Dollars::NAN, unrealized_loss: Dollars::NAN, @@ -20,7 +20,7 @@ impl UnrealizedState { pub const ZERO: Self = Self { supply_in_profit: Sats::ZERO, - supply_even: Sats::ZERO, + supply_breakeven: Sats::ZERO, supply_in_loss: Sats::ZERO, unrealized_profit: Dollars::ZERO, unrealized_loss: Dollars::ZERO, diff --git a/crates/brk_indexer/examples/indexer.rs b/crates/brk_indexer/examples/indexer.rs index 9b9b82a7a..86c183f4f 100644 --- a/crates/brk_indexer/examples/indexer.rs +++ b/crates/brk_indexer/examples/indexer.rs @@ -22,7 +22,7 @@ fn main() -> Result<()> { let blocks_dir = bitcoin_dir.join("blocks"); let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk"); - fs::create_dir_all(outputs_dir)?; + fs::create_dir_all(&outputs_dir)?; // let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk"); let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new( @@ -35,9 +35,9 @@ fn main() -> Result<()> { let parser = Parser::new(blocks_dir, Some(outputs_dir.to_path_buf()), rpc); - fs::create_dir_all(outputs_dir)?; + fs::create_dir_all(&outputs_dir)?; - let mut indexer = Indexer::forced_import(outputs_dir)?; + let mut indexer = Indexer::forced_import(&outputs_dir)?; loop { let i = Instant::now(); diff --git a/crates/brk_indexer/src/lib.rs b/crates/brk_indexer/src/lib.rs index 9eeb67aca..e8cb19215 100644 --- a/crates/brk_indexer/src/lib.rs +++ b/crates/brk_indexer/src/lib.rs @@ -5,7 +5,7 @@ use std::{collections::BTreeMap, path::Path, str::FromStr, thread, time::Instant use bitcoin::{Transaction, TxIn, TxOut}; use brk_error::{Error, Result}; -use brk_parser::Parser; +use brk_parser::{BlockExtended, Parser}; use brk_store::AnyStore; use brk_structs::{ AddressBytes, AddressBytesHash, BlockHash, BlockHashPrefix, Height, InputIndex, OutputIndex, @@ -14,7 +14,7 @@ use brk_structs::{ }; use log::{error, info}; use rayon::prelude::*; -use vecdb::{AnyVec, Database, Exit, GenericStoredVec, PAGE_SIZE, Reader, VecIterator}; +use vecdb::{AnyVec, Exit, GenericStoredVec, Reader, VecIterator}; mod indexes; mod stores; mod vecs; @@ -29,7 +29,6 @@ const VERSION: Version = Version::ONE; #[derive(Clone)] pub struct Indexer { - pub db: Database, pub vecs: Vecs, pub stores: Stores, } @@ -38,18 +37,15 @@ impl Indexer { pub fn forced_import(outputs_dir: &Path) -> Result { info!("Importing indexer..."); - let db = Database::open(&outputs_dir.join("indexed/vecs"))?; - db.set_min_len(PAGE_SIZE * 50_000_000)?; - info!("Opened database"); + let path = outputs_dir.join("indexed"); - let vecs = Vecs::forced_import(&db, VERSION + Version::ZERO)?; + let vecs = Vecs::forced_import(&path, VERSION + Version::ZERO)?; info!("Imported vecs"); - let stores = - Stores::forced_import(&outputs_dir.join("indexed/stores"), VERSION + Version::ZERO)?; + let stores = Stores::forced_import(&path, VERSION + Version::ZERO)?; info!("Imported stores"); - Ok(Self { vecs, stores, db }) + Ok(Self { vecs, stores }) } pub fn index( @@ -59,16 +55,9 @@ impl Indexer { exit: &Exit, check_collisions: bool, ) -> Result { - let db = self.db.clone(); - - // dbg!(self.db.regions().id_to_index()); - // dbg!(self.db.layout()); - let starting_indexes = Indexes::try_from((&mut self.vecs, &self.stores, rpc)) .unwrap_or_else(|_report| Indexes::default()); - // dbg!(&starting_indexes); - let lock = exit.lock(); self.stores .rollback_if_needed(&mut self.vecs, &starting_indexes)?; @@ -108,7 +97,6 @@ impl Indexer { vecs.flush(height)?; info!("Flushed vecs in {}s", i.elapsed().as_secs()); let i = Instant::now(); - db.flush()?; info!("Flushed db in {}s", i.elapsed().as_secs()); Ok(()) }; @@ -210,6 +198,10 @@ impl Indexer { .blockhashprefix_to_height .insert_if_needed(blockhash_prefix, height, height); + stores + .height_to_coinbase_tag + .insert_if_needed( height, block.coinbase_tag().into(), height); + vecs.height_to_blockhash.push_if_needed(height, blockhash)?; vecs.height_to_difficulty .push_if_needed(height, block.header.difficulty_float().into())?; @@ -797,7 +789,7 @@ impl Indexer { } let i = Instant::now(); - db.punch_holes()?; + self.vecs.punch_holes()?; info!("Punched holes in db in {}s", i.elapsed().as_secs()); Ok(starting_indexes) diff --git a/crates/brk_indexer/src/stores.rs b/crates/brk_indexer/src/stores.rs index 63af451cc..887b39dae 100644 --- a/crates/brk_indexer/src/stores.rs +++ b/crates/brk_indexer/src/stores.rs @@ -4,11 +4,12 @@ use brk_error::Result; use brk_store::{AnyStore, Store}; use brk_structs::{ AddressBytes, AddressBytesHash, BlockHashPrefix, ByAddressType, Height, OutputIndex, - OutputType, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit, Version, + OutputType, StoredString, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit, + Version, }; use fjall::{PersistMode, TransactionalKeyspace}; use rayon::prelude::*; -use vecdb::VecIterator; +use vecdb::{AnyVec, StoredIndex, VecIterator}; use crate::Indexes; @@ -20,6 +21,7 @@ pub struct Stores { pub addressbyteshash_to_typeindex: Store, pub blockhashprefix_to_height: Store, + pub height_to_coinbase_tag: Store, pub txidprefix_to_txindex: Store, pub addresstype_to_typeindex_with_outputindex: ByAddressType>, @@ -28,14 +30,16 @@ pub struct Stores { const VERSION: Version = Version::ZERO; impl Stores { - pub fn forced_import(path: &Path, version: Version) -> Result { - fs::create_dir_all(path)?; + pub fn forced_import(parent: &Path, version: Version) -> Result { + let path = parent.join("stores"); - let keyspace = match brk_store::open_keyspace(path) { + fs::create_dir_all(&path)?; + + let keyspace = match brk_store::open_keyspace(&path) { Ok(keyspace) => keyspace, Err(_) => { - fs::remove_dir_all(path)?; - return Self::forced_import(path, version); + fs::remove_dir_all(&path)?; + return Self::forced_import(&path, version); } }; @@ -43,7 +47,7 @@ impl Stores { let addressbyteshash_to_typeindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "addressbyteshash_to_typeindex", version + VERSION + Version::ZERO, None, @@ -52,7 +56,7 @@ impl Stores { let blockhashprefix_to_height = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "blockhashprefix_to_height", version + VERSION + Version::ZERO, None, @@ -61,7 +65,7 @@ impl Stores { let txidprefix_to_txindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "txidprefix_to_txindex", version + VERSION + Version::ZERO, None, @@ -70,7 +74,7 @@ impl Stores { let p2aaddressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2aaddressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -79,7 +83,7 @@ impl Stores { let p2pk33addressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2pk33addressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -88,7 +92,7 @@ impl Stores { let p2pk65addressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2pk65addressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -97,7 +101,7 @@ impl Stores { let p2pkhaddressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2pkhaddressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -106,7 +110,7 @@ impl Stores { let p2shaddressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2shaddressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -115,7 +119,7 @@ impl Stores { let p2traddressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2traddressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -124,7 +128,7 @@ impl Stores { let p2wpkhaddressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2wpkhaddressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), @@ -133,16 +137,25 @@ impl Stores { let p2wshaddressindex_with_outputindex = scope.spawn(|| { Store::import( &keyspace, - path, + &path, "p2wshaddressindex_with_outputindex", version + VERSION + Version::ZERO, Some(false), ) }); + let height_to_coinbase_tag = Store::import( + &keyspace, + &path, + "height_to_coinbase_tag", + version + VERSION + Version::ZERO, + None, + )?; + Ok(Self { keyspace: keyspace.clone(), + height_to_coinbase_tag, addressbyteshash_to_typeindex: addressbyteshash_to_typeindex.join().unwrap()?, blockhashprefix_to_height: blockhashprefix_to_height.join().unwrap()?, txidprefix_to_txindex: txidprefix_to_txindex.join().unwrap()?, @@ -182,11 +195,9 @@ impl Stores { .map_err(|e| e.into()) } - fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 11] { + fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 12] { [ &self.addressbyteshash_to_typeindex, - &self.blockhashprefix_to_height, - &self.txidprefix_to_txindex, &self.addresstype_to_typeindex_with_outputindex.p2a, &self.addresstype_to_typeindex_with_outputindex.p2pk33, &self.addresstype_to_typeindex_with_outputindex.p2pk65, @@ -195,14 +206,15 @@ impl Stores { &self.addresstype_to_typeindex_with_outputindex.p2tr, &self.addresstype_to_typeindex_with_outputindex.p2wpkh, &self.addresstype_to_typeindex_with_outputindex.p2wsh, + &self.blockhashprefix_to_height, + &self.height_to_coinbase_tag, + &self.txidprefix_to_txindex, ] } - fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 11] { + fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 12] { [ &mut self.addressbyteshash_to_typeindex, - &mut self.blockhashprefix_to_height, - &mut self.txidprefix_to_txindex, &mut self.addresstype_to_typeindex_with_outputindex.p2a, &mut self.addresstype_to_typeindex_with_outputindex.p2pk33, &mut self.addresstype_to_typeindex_with_outputindex.p2pk65, @@ -211,6 +223,9 @@ impl Stores { &mut self.addresstype_to_typeindex_with_outputindex.p2tr, &mut self.addresstype_to_typeindex_with_outputindex.p2wpkh, &mut self.addresstype_to_typeindex_with_outputindex.p2wsh, + &mut self.blockhashprefix_to_height, + &mut self.height_to_coinbase_tag, + &mut self.txidprefix_to_txindex, ] } @@ -222,6 +237,7 @@ impl Stores { if self.addressbyteshash_to_typeindex.is_empty()? && self.blockhashprefix_to_height.is_empty()? && self.txidprefix_to_txindex.is_empty()? + && self.height_to_coinbase_tag.is_empty()? && self .addresstype_to_typeindex_with_outputindex .p2a @@ -266,6 +282,12 @@ impl Stores { self.blockhashprefix_to_height.remove(blockhashprefix); }); + (starting_indexes.height.unwrap_to_usize()..vecs.height_to_blockhash.len()) + .map(Height::from) + .for_each(|h| { + self.height_to_coinbase_tag.remove(h); + }); + if let Some(mut index) = vecs .height_to_first_p2pk65addressindex .iter() diff --git a/crates/brk_indexer/src/vecs.rs b/crates/brk_indexer/src/vecs.rs index 636d4887a..d3ea73d5c 100644 --- a/crates/brk_indexer/src/vecs.rs +++ b/crates/brk_indexer/src/vecs.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use brk_error::Result; use brk_structs::{ AddressBytes, BlockHash, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex, @@ -9,7 +11,8 @@ use brk_structs::{ }; use rayon::prelude::*; use vecdb::{ - AnyCollectableVec, AnyStoredVec, CompressedVec, Database, GenericStoredVec, RawVec, Stamp, + AnyCollectableVec, AnyStoredVec, CompressedVec, Database, GenericStoredVec, PAGE_SIZE, RawVec, + Stamp, }; use crate::Indexes; @@ -18,6 +21,8 @@ const VERSION: Version = Version::ZERO; #[derive(Clone)] pub struct Vecs { + db: Database, + pub emptyoutputindex_to_txindex: CompressedVec, pub height_to_blockhash: RawVec, pub height_to_difficulty: CompressedVec, @@ -67,225 +72,240 @@ pub struct Vecs { } impl Vecs { - pub fn forced_import(db: &Database, version: Version) -> Result { - Ok(Self { + pub fn forced_import(parent: &Path, version: Version) -> Result { + let db = Database::open(&parent.join("vecs"))?; + + db.set_min_len(PAGE_SIZE * 50_000_000)?; + + let this = Self { emptyoutputindex_to_txindex: CompressedVec::forced_import( - db, + &db, "txindex", version + VERSION + Version::ZERO, )?, height_to_blockhash: RawVec::forced_import( - db, + &db, "blockhash", version + VERSION + Version::ZERO, )?, height_to_difficulty: CompressedVec::forced_import( - db, + &db, "difficulty", version + VERSION + Version::ZERO, )?, height_to_first_emptyoutputindex: CompressedVec::forced_import( - db, + &db, "first_emptyoutputindex", version + VERSION + Version::ZERO, )?, height_to_first_inputindex: CompressedVec::forced_import( - db, + &db, "first_inputindex", version + VERSION + Version::ZERO, )?, height_to_first_opreturnindex: CompressedVec::forced_import( - db, + &db, "first_opreturnindex", version + VERSION + Version::ZERO, )?, height_to_first_outputindex: CompressedVec::forced_import( - db, + &db, "first_outputindex", version + VERSION + Version::ZERO, )?, height_to_first_p2aaddressindex: CompressedVec::forced_import( - db, + &db, "first_p2aaddressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2msoutputindex: CompressedVec::forced_import( - db, + &db, "first_p2msoutputindex", version + VERSION + Version::ZERO, )?, height_to_first_p2pk33addressindex: CompressedVec::forced_import( - db, + &db, "first_p2pk33addressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2pk65addressindex: CompressedVec::forced_import( - db, + &db, "first_p2pk65addressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2pkhaddressindex: CompressedVec::forced_import( - db, + &db, "first_p2pkhaddressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2shaddressindex: CompressedVec::forced_import( - db, + &db, "first_p2shaddressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2traddressindex: CompressedVec::forced_import( - db, + &db, "first_p2traddressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2wpkhaddressindex: CompressedVec::forced_import( - db, + &db, "first_p2wpkhaddressindex", version + VERSION + Version::ZERO, )?, height_to_first_p2wshaddressindex: CompressedVec::forced_import( - db, + &db, "first_p2wshaddressindex", version + VERSION + Version::ZERO, )?, height_to_first_txindex: CompressedVec::forced_import( - db, + &db, "first_txindex", version + VERSION + Version::ZERO, )?, height_to_first_unknownoutputindex: CompressedVec::forced_import( - db, + &db, "first_unknownoutputindex", version + VERSION + Version::ZERO, )?, height_to_timestamp: CompressedVec::forced_import( - db, + &db, "timestamp", version + VERSION + Version::ZERO, )?, height_to_total_size: CompressedVec::forced_import( - db, + &db, "total_size", version + VERSION + Version::ZERO, )?, height_to_weight: CompressedVec::forced_import( - db, + &db, "weight", version + VERSION + Version::ZERO, )?, inputindex_to_outputindex: RawVec::forced_import( - db, + &db, "outputindex", version + VERSION + Version::ZERO, )?, opreturnindex_to_txindex: CompressedVec::forced_import( - db, + &db, "txindex", version + VERSION + Version::ZERO, )?, outputindex_to_outputtype: RawVec::forced_import( - db, + &db, "outputtype", version + VERSION + Version::ZERO, )?, outputindex_to_typeindex: RawVec::forced_import( - db, + &db, "typeindex", version + VERSION + Version::ZERO, )?, outputindex_to_value: RawVec::forced_import( - db, + &db, "value", version + VERSION + Version::ZERO, )?, p2aaddressindex_to_p2abytes: RawVec::forced_import( - db, + &db, "p2abytes", version + VERSION + Version::ZERO, )?, p2msoutputindex_to_txindex: CompressedVec::forced_import( - db, + &db, "txindex", version + VERSION + Version::ZERO, )?, p2pk33addressindex_to_p2pk33bytes: RawVec::forced_import( - db, + &db, "p2pk33bytes", version + VERSION + Version::ZERO, )?, p2pk65addressindex_to_p2pk65bytes: RawVec::forced_import( - db, + &db, "p2pk65bytes", version + VERSION + Version::ZERO, )?, p2pkhaddressindex_to_p2pkhbytes: RawVec::forced_import( - db, + &db, "p2pkhbytes", version + VERSION + Version::ZERO, )?, p2shaddressindex_to_p2shbytes: RawVec::forced_import( - db, + &db, "p2shbytes", version + VERSION + Version::ZERO, )?, p2traddressindex_to_p2trbytes: RawVec::forced_import( - db, + &db, "p2trbytes", version + VERSION + Version::ZERO, )?, p2wpkhaddressindex_to_p2wpkhbytes: RawVec::forced_import( - db, + &db, "p2wpkhbytes", version + VERSION + Version::ZERO, )?, p2wshaddressindex_to_p2wshbytes: RawVec::forced_import( - db, + &db, "p2wshbytes", version + VERSION + Version::ZERO, )?, txindex_to_base_size: CompressedVec::forced_import( - db, + &db, "base_size", version + VERSION + Version::ZERO, )?, txindex_to_first_inputindex: CompressedVec::forced_import( - db, + &db, "first_inputindex", version + VERSION + Version::ZERO, )?, txindex_to_first_outputindex: CompressedVec::forced_import( - db, + &db, "first_outputindex", version + VERSION + Version::ZERO, )?, txindex_to_is_explicitly_rbf: CompressedVec::forced_import( - db, + &db, "is_explicitly_rbf", version + VERSION + Version::ZERO, )?, txindex_to_rawlocktime: CompressedVec::forced_import( - db, + &db, "rawlocktime", version + VERSION + Version::ZERO, )?, txindex_to_total_size: CompressedVec::forced_import( - db, + &db, "total_size", version + VERSION + Version::ZERO, )?, - txindex_to_txid: RawVec::forced_import(db, "txid", version + VERSION + Version::ZERO)?, + txindex_to_txid: RawVec::forced_import(&db, "txid", version + VERSION + Version::ZERO)?, txindex_to_txversion: CompressedVec::forced_import( - db, + &db, "txversion", version + VERSION + Version::ZERO, )?, unknownoutputindex_to_txindex: CompressedVec::forced_import( - db, + &db, "txindex", version + VERSION + Version::ZERO, )?, - }) + + db, + }; + + // self.db.retain_regions( + // this.vecs() + // .into_iter() + // .flat_map(|v| v.region_names()) + // .collect(), + // )?; + + Ok(this) } pub fn rollback_if_needed(&mut self, starting_indexes: &Indexes) -> Result<()> { @@ -438,6 +458,7 @@ impl Vecs { self.mut_vecs() .into_par_iter() .try_for_each(|vec| vec.stamped_flush(Stamp::from(height)))?; + self.db.flush()?; Ok(()) } @@ -452,6 +473,11 @@ impl Vecs { .unwrap() } + pub fn punch_holes(&self) -> Result<()> { + self.db.punch_holes()?; + Ok(()) + } + pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> { vec![ &self.emptyoutputindex_to_txindex, diff --git a/crates/brk_interface/Cargo.toml b/crates/brk_interface/Cargo.toml index a2f843e34..d14a3373a 100644 --- a/crates/brk_interface/Cargo.toml +++ b/crates/brk_interface/Cargo.toml @@ -21,3 +21,4 @@ serde = { workspace = true } serde_json = { workspace = true } serde_with = "3.14.0" tabled = "0.20.0" +nucleo-matcher = "0.3.1" diff --git a/crates/brk_interface/src/index.rs b/crates/brk_interface/src/index.rs index 9ab48a65c..937bbf7d6 100644 --- a/crates/brk_interface/src/index.rs +++ b/crates/brk_interface/src/index.rs @@ -2,11 +2,11 @@ use std::fmt::{self, Debug}; use brk_error::Error; use brk_structs::{ - DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex, - MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, - P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, - P2WSHAddressIndex, Printable, QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex, - WeekIndex, YearIndex, + DateIndex, DecadeIndex, DifficultyEpoch, EmptyAddressIndex, EmptyOutputIndex, HalvingEpoch, + Height, InputIndex, LoadedAddressIndex, MonthIndex, OpReturnIndex, OutputIndex, + P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, + P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, Printable, + QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex, }; use schemars::JsonSchema; use serde::Deserialize; @@ -63,10 +63,14 @@ pub enum Index { WeekIndex, #[schemars(description = "Year index")] YearIndex, + #[schemars(description = "Loaded Address Index")] + LoadedAddressIndex, + #[schemars(description = "Empty Address Index")] + EmptyAddressIndex, } impl Index { - pub fn all() -> [Self; 25] { + pub fn all() -> [Self; 27] { [ Self::DateIndex, Self::DecadeIndex, @@ -93,6 +97,8 @@ impl Index { Self::UnknownOutputIndex, Self::WeekIndex, Self::YearIndex, + Self::LoadedAddressIndex, + Self::EmptyAddressIndex, ] } @@ -123,6 +129,8 @@ impl Index { Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(), Self::WeekIndex => WeekIndex::to_possible_strings(), Self::YearIndex => YearIndex::to_possible_strings(), + Self::LoadedAddressIndex => LoadedAddressIndex::to_possible_strings(), + Self::EmptyAddressIndex => EmptyAddressIndex::to_possible_strings(), } } @@ -186,6 +194,12 @@ impl TryFrom<&str> for Index { v if (Self::UnknownOutputIndex).possible_values().contains(&v) => { Self::UnknownOutputIndex } + v if (Self::LoadedAddressIndex).possible_values().contains(&v) => { + Self::LoadedAddressIndex + } + v if (Self::EmptyAddressIndex).possible_values().contains(&v) => { + Self::EmptyAddressIndex + } _ => return Err(Error::Str("Bad index")), }) } diff --git a/crates/brk_interface/src/lib.rs b/crates/brk_interface/src/lib.rs index 8b916166a..2b3e67f48 100644 --- a/crates/brk_interface/src/lib.rs +++ b/crates/brk_interface/src/lib.rs @@ -3,9 +3,13 @@ use std::collections::BTreeMap; use brk_computer::Computer; -use brk_error::Result; +use brk_error::{Error, Result}; use brk_indexer::Indexer; use brk_structs::Height; +use nucleo_matcher::{ + Config, Matcher, + pattern::{Atom, AtomKind, CaseMatching, Normalization, Pattern}, +}; use tabled::settings::Style; use vecdb::{AnyCollectableVec, AnyStoredVec}; @@ -53,38 +57,65 @@ impl<'a> Interface<'a> { Height::from(self.indexer.vecs.height_to_blockhash.stamp()) } - pub fn search(&self, params: &Params) -> Vec<(String, &&dyn AnyCollectableVec)> { - let tuples = params - .ids - .iter() - .flat_map(|s| { - s.to_lowercase() - .replace("-", "_") - .split_whitespace() - .flat_map(|s| { - s.split(',') - .flat_map(|s| s.split('+').map(|s| s.to_string())) - }) - .collect::>() - }) - .map(|mut id| { - let mut res = self.vecs.id_to_index_to_vec.get(id.as_str()); - if res.is_none() - && let Ok(index) = Index::try_from(id.as_str()) - { - id = index.possible_values().last().unwrap().to_string(); - res = self.vecs.id_to_index_to_vec.get(id.as_str()) - } - (id, res) - }) - .filter(|(_, opt)| opt.is_some()) - .map(|(id, vec)| (id, vec.unwrap())) - .collect::>(); + pub fn search(&self, params: &Params) -> Result> { + let ids_to_vec = self + .vecs + .index_to_id_to_vec + .get(¶ms.index) + .ok_or(Error::String(format!( + "Index \"{}\" isn't a valid index", + params.index + )))?; - tuples - .iter() - .flat_map(|(str, i_to_v)| i_to_v.get(¶ms.index).map(|vec| (str.to_owned(), vec))) - .collect::>() + let maybe_ids = params.ids.iter().flat_map(|s| { + s.to_lowercase() + .replace("-", "_") + .split_whitespace() + .flat_map(|s| { + s.split(',') + .flat_map(|s| s.split('+').map(|s| s.to_string())) + }) + .collect::>() + }); + + maybe_ids + .map(|id| { + let vec = ids_to_vec.get(id.as_str()).ok_or_else(|| { + let mut message = format!( + "No vec named \"{}\" indexed by \"{}\" found.\n", + // tell if id found in another index + id, + params.index + ); + + let mut matcher = Matcher::new(Config::DEFAULT); + + let matches = Pattern::new( + id.as_str(), + CaseMatching::Ignore, + Normalization::Smart, + AtomKind::Fuzzy, + ) + .match_list(ids_to_vec.keys(), &mut matcher) + .into_iter() + .take(10) + .map(|(s, _)| s) + .collect::>(); + + if !matches.is_empty() { + message += + &format!("\nMaybe you meant one of the following: {matches:#?} ?\n"); + } + + if let Some(index_to_vec) = self.id_to_index_to_vec().get(id.as_str()) { + message += &format!("\nBut there is a vec named {id} which supports the following indexes: {:#?}\n", index_to_vec.keys()); + } + + Error::String(message) + }); + vec.map(|vec| (id, vec)) + }) + .collect::>>() } pub fn format( @@ -183,7 +214,7 @@ impl<'a> Interface<'a> { } pub fn search_and_format(&self, params: Params) -> Result { - self.format(self.search(¶ms), ¶ms.rest) + self.format(self.search(¶ms)?, ¶ms.rest) } pub fn id_to_index_to_vec(&self) -> &BTreeMap<&str, IndexToVec<'_>> { diff --git a/crates/brk_parser/examples/main.rs b/crates/brk_parser/examples/main.rs index 07a8ca4ea..4baa0eb5d 100644 --- a/crates/brk_parser/examples/main.rs +++ b/crates/brk_parser/examples/main.rs @@ -1,6 +1,5 @@ use std::path::Path; -use bitcoin::{Block, consensus::serde::hex, script::Instruction}; use bitcoincore_rpc::{Auth, Client, Result}; use brk_parser::Parser; use brk_structs::Height; @@ -28,14 +27,9 @@ fn main() -> Result<()> { .parse(start, end) .iter() .for_each(|(height, _block, hash)| { - println!("{height}: {}", _block.get_coinbase_message()); + println!("{height}: {}", hash); }); - println!( - "391487: {}", - parser.get(Height::new(391487)).get_coinbase_message() - ); - let block_0 = parser.get(Height::new(0)); println!( @@ -50,8 +44,6 @@ fn main() -> Result<()> { .script_pubkey ); - println!("{}", block_0.get_coinbase_message()); - let block_158251 = parser.get(Height::new(158251)); println!( "{}", @@ -64,7 +56,6 @@ fn main() -> Result<()> { .unwrap() .script_pubkey ); - println!("{}", block_158251.get_coinbase_message()); let block_840_000 = parser.get(Height::new(840_004)); @@ -80,27 +71,7 @@ fn main() -> Result<()> { .value ); - println!("{}", block_840_000.get_coinbase_message()); - dbg!(i.elapsed()); Ok(()) } - -pub trait BlockExtended { - fn get_coinbase_message(&self) -> String; -} - -impl BlockExtended for Block { - fn get_coinbase_message(&self) -> String { - let Some(input) = self.txdata.first().and_then(|tx| tx.input.first()) else { - return String::new(); - }; - let bytes = input.script_sig.as_bytes(); - String::from_utf8_lossy(bytes) - .chars() - .filter(|&c| c != '\u{FFFD}' && (c >= ' ' || c == '\n' || c == '\r' || c == '\t')) - .take(1_024) - .collect() - } -} diff --git a/crates/brk_parser/src/block.rs b/crates/brk_parser/src/block.rs new file mode 100644 index 000000000..b2c1decbf --- /dev/null +++ b/crates/brk_parser/src/block.rs @@ -0,0 +1,19 @@ +use bitcoin::Block; + +pub trait BlockExtended { + fn coinbase_tag(&self) -> String; +} + +impl BlockExtended for Block { + fn coinbase_tag(&self) -> String { + let Some(input) = self.txdata.first().and_then(|tx| tx.input.first()) else { + return String::new(); + }; + let bytes = input.script_sig.as_bytes(); + String::from_utf8_lossy(bytes) + .chars() + .filter(|&c| c != '\u{FFFD}' && (c >= ' ' || c == '\n' || c == '\r' || c == '\t')) + .take(1_024) + .collect() + } +} diff --git a/crates/brk_parser/src/lib.rs b/crates/brk_parser/src/lib.rs index fd9408c52..3d561510a 100644 --- a/crates/brk_parser/src/lib.rs +++ b/crates/brk_parser/src/lib.rs @@ -14,6 +14,7 @@ mod blk_index_to_blk_path; mod blk_index_to_blk_recap; mod blk_metadata; mod blk_recap; +mod block; mod block_state; mod error; mod utils; @@ -22,6 +23,7 @@ mod xor_index; use blk_index_to_blk_recap::*; use blk_metadata::*; +pub use block::*; use block_state::*; pub use error::*; use utils::*; diff --git a/crates/brk_server/src/api/interface.rs b/crates/brk_server/src/api/interface.rs index a95571ab7..38ec945cc 100644 --- a/crates/brk_server/src/api/interface.rs +++ b/crates/brk_server/src/api/interface.rs @@ -16,7 +16,7 @@ use crate::{HeaderMapExtended, ResponseExtended}; use super::AppState; -const MAX_WEIGHT: usize = 320_000; +const MAX_WEIGHT: usize = 65 * 10_000; pub async fn handler( uri: Uri, @@ -43,7 +43,7 @@ fn req_to_response_res( interface, cache, .. }: AppState, ) -> Result { - let vecs = interface.search(¶ms); + let vecs = interface.search(¶ms)?; if vecs.is_empty() { return Ok(Json(vec![] as Vec).into_response()); @@ -61,9 +61,9 @@ fn req_to_response_res( .sum::(); if weight > MAX_WEIGHT { - return Err(Error::Str( - "Request is too heavy, max weight is {MAX_WEIGHT} bytes", - )); + return Err(Error::String(format!( + "Request is too heavy, max weight is {MAX_WEIGHT} bytes" + ))); } // TODO: height should be from vec, but good enough for now diff --git a/crates/brk_server/src/api/mod.rs b/crates/brk_server/src/api/mod.rs index 95fa20f91..8a3a5579b 100644 --- a/crates/brk_server/src/api/mod.rs +++ b/crates/brk_server/src/api/mod.rs @@ -106,16 +106,6 @@ impl ApiRoutes for Router { }, ), ) - .route( - "/health", - get(|| async { - Json(serde_json::json!({ - "status": "healthy", - "service": "brk-server", - "timestamp": jiff::Timestamp::now().to_string() - })) - }), - ) .route( "/api", get(|| async { @@ -124,9 +114,5 @@ impl ApiRoutes for Router { ) }), ) - .route( - "/discord", - get(|| async { Redirect::temporary("https://discord.com/invite/HaR3wpH3nr") }), - ) } } diff --git a/crates/brk_server/src/lib.rs b/crates/brk_server/src/lib.rs index 8d1f504bc..d63d05544 100644 --- a/crates/brk_server/src/lib.rs +++ b/crates/brk_server/src/lib.rs @@ -11,6 +11,7 @@ use axum::{ body::{Body, Bytes}, http::{Request, Response, StatusCode, Uri}, middleware::Next, + response::Redirect, routing::get, serve, }; @@ -47,7 +48,7 @@ impl Server { Self(AppState { interface: Box::leak(Box::new(interface)), path: files_path, - cache: Arc::new(Cache::new(10_000)), + cache: Arc::new(Cache::new(5_000)), }) } @@ -98,6 +99,33 @@ impl Server { .add_files_routes(state.path.as_ref()) .add_mcp_routes(state.interface, mcp) .route("/version", get(Json(VERSION))) + .route( + "/health", + get(Json(serde_json::json!({ + "status": "healthy", + "service": "brk-server", + "timestamp": jiff::Timestamp::now().to_string() + }))), + ) + .route( + "/discord", + get(Redirect::temporary("https://discord.gg/WACpShCB7M")), + ) + .route("/crates", get(Redirect::temporary("https://crates.io/crates/brk"))) + .route( + "/status", + get(Redirect::temporary("https://status.bitview.space")), + ) + .route("/github", get(Redirect::temporary("https://github.com/bitcoinresearchkit/brk"))) + .route( + "/cli", + get(Redirect::temporary("https://crates.io/crates/brk_cli")), + ) + .route( + "/hosting", + get(Redirect::temporary("https://github.com/bitcoinresearchkit/brk?tab=readme-ov-file#hosting-as-a-service")), + ) + .route("/nostr", get(Redirect::temporary("https://primal.net/p/npub1jagmm3x39lmwfnrtvxcs9ac7g300y3dusv9lgzhk2e4x5frpxlrqa73v44"))) .with_state(state) .layer(compression_layer) .layer(response_uri_layer) diff --git a/crates/brk_structs/src/structs/emptyaddressindex.rs b/crates/brk_structs/src/structs/emptyaddressindex.rs index 41fcd7fe9..7a192c5cf 100644 --- a/crates/brk_structs/src/structs/emptyaddressindex.rs +++ b/crates/brk_structs/src/structs/emptyaddressindex.rs @@ -1,8 +1,8 @@ use std::ops::Add; -use vecdb::{CheckedSub, Printable}; use derive_deref::Deref; use serde::Serialize; +use vecdb::{CheckedSub, Printable, StoredCompressed}; use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -22,6 +22,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, + StoredCompressed, )] pub struct EmptyAddressIndex(TypeIndex); diff --git a/crates/brk_structs/src/structs/height.rs b/crates/brk_structs/src/structs/height.rs index 04fbd3ef3..fb9749361 100644 --- a/crates/brk_structs/src/structs/height.rs +++ b/crates/brk_structs/src/structs/height.rs @@ -227,13 +227,19 @@ impl TryFrom<&std::path::Path> for Height { } impl From for Height { - fn from(value: byteview::ByteView) -> Self { + fn from(value: ByteView) -> Self { Self(u32::from_be_bytes(copy_first_4bytes(&value).unwrap())) } } impl From for ByteView { fn from(value: Height) -> Self { + Self::from(&value) + } +} + +impl From<&Height> for ByteView { + fn from(value: &Height) -> Self { Self::new(&value.0.to_be_bytes()) } } diff --git a/crates/brk_structs/src/structs/loadedaddressdata.rs b/crates/brk_structs/src/structs/loadedaddressdata.rs index 4a61316c8..d3bb6d645 100644 --- a/crates/brk_structs/src/structs/loadedaddressdata.rs +++ b/crates/brk_structs/src/structs/loadedaddressdata.rs @@ -11,7 +11,8 @@ pub struct LoadedAddressData { pub sent: Sats, pub received: Sats, pub realized_cap: Dollars, - pub outputs_len: u32, + pub utxos: u32, + #[serde(skip)] padding: u32, } @@ -41,12 +42,12 @@ impl LoadedAddressData { #[inline] pub fn has_0_utxos(&self) -> bool { - self.outputs_len == 0 + self.utxos == 0 } pub fn receive(&mut self, amount: Sats, price: Option) { self.received += amount; - self.outputs_len += 1; + self.utxos += 1; if let Some(price) = price { let added = price * amount; self.realized_cap += added; @@ -62,7 +63,7 @@ impl LoadedAddressData { return Err(Error::Str("Previous_amount smaller than sent amount")); } self.sent += amount; - self.outputs_len -= 1; + self.utxos -= 1; if let Some(previous_price) = previous_price { let subtracted = previous_price * amount; let realized_cap = self.realized_cap.checked_sub(subtracted).unwrap(); @@ -94,7 +95,7 @@ impl From<&EmptyAddressData> for LoadedAddressData { sent: value.transfered, received: value.transfered, realized_cap: Dollars::ZERO, - outputs_len: 0, + utxos: 0, padding: 0, } } diff --git a/crates/brk_structs/src/structs/loadedaddressindex.rs b/crates/brk_structs/src/structs/loadedaddressindex.rs index 15b028ffa..0424a0278 100644 --- a/crates/brk_structs/src/structs/loadedaddressindex.rs +++ b/crates/brk_structs/src/structs/loadedaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, Printable}; +use vecdb::{CheckedSub, Printable, StoredCompressed}; use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -22,6 +22,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, + StoredCompressed, )] pub struct LoadedAddressIndex(TypeIndex); diff --git a/crates/brk_structs/src/structs/mod.rs b/crates/brk_structs/src/structs/mod.rs index 155563604..c902c0079 100644 --- a/crates/brk_structs/src/structs/mod.rs +++ b/crates/brk_structs/src/structs/mod.rs @@ -43,6 +43,7 @@ mod stored_bool; mod stored_f32; mod stored_f64; mod stored_i16; +mod stored_string; mod stored_u16; mod stored_u32; mod stored_u64; @@ -105,6 +106,7 @@ pub use stored_bool::*; pub use stored_f32::*; pub use stored_f64::*; pub use stored_i16::*; +pub use stored_string::*; pub use stored_u8::*; pub use stored_u16::*; pub use stored_u32::*; diff --git a/crates/brk_structs/src/structs/stored_string.rs b/crates/brk_structs/src/structs/stored_string.rs new file mode 100644 index 000000000..ca55470af --- /dev/null +++ b/crates/brk_structs/src/structs/stored_string.rs @@ -0,0 +1,56 @@ +use byteview::ByteView; +use derive_deref::Deref; +use serde::Serialize; +use vecdb::Printable; + +#[derive(Default, Debug, Deref, Clone, Serialize)] +pub struct StoredString(String); + +impl StoredString { + pub fn new(string: String) -> Self { + Self(string) + } + + pub fn as_str(&self) -> &str { + self + } + + pub fn as_string(&self) -> &String { + self + } +} + +impl From for StoredString { + fn from(value: String) -> Self { + Self(value) + } +} + +impl From for StoredString { + fn from(value: ByteView) -> Self { + let bytes = &*value; + Self(String::from_utf8_lossy(bytes).into_owned()) + } +} + +impl From for ByteView { + fn from(value: StoredString) -> Self { + Self::from(&value) + } +} + +impl From<&StoredString> for ByteView { + fn from(value: &StoredString) -> Self { + Self::new(value.as_bytes()) + } +} + +impl Printable for StoredString { + fn to_string() -> &'static str { + "string" + } + + fn to_possible_strings() -> &'static [&'static str] { + &["string"] + } +} diff --git a/websites/bitview/scripts/chart.js b/websites/bitview/scripts/chart.js index 2dba52cbf..654f181c5 100644 --- a/websites/bitview/scripts/chart.js +++ b/websites/bitview/scripts/chart.js @@ -141,7 +141,7 @@ export function init({ if (!t) return; from.set(t.from); to.set(t.to); - }), + }, 250), ); elements.charts.append(fieldset); @@ -241,7 +241,7 @@ export function init({ break; } case /** @satisfies {DateIndex} */ (0): { - iseries.update(latest); + iseries.update(last); break; } default: { @@ -277,7 +277,7 @@ export function init({ iseries.update(last); } else { latest.time = time; - iseries.update(latest); + iseries.update(last); } } } @@ -329,29 +329,32 @@ export function init({ /** @type {Series | undefined} */ let series; + console.log({ topUnit, topSeriesType }); + switch (topUnit) { case "USD": { switch (topSeriesType) { + case null: case CANDLE: { series = chart.addCandlestickSeries({ - vecId: "ohlc", + vecId: "price_ohlc", name: "Price", unit: topUnit, setDataCallback: printLatest, order: 0, }); - break; } case LINE: { series = chart.addLineSeries({ - vecId: "close", + vecId: "price_close", name: "Price", unit: topUnit, color: colors.default, setDataCallback: printLatest, options: { priceLineVisible: true, + lastValueVisible: true, }, order: 0, }); @@ -361,6 +364,7 @@ export function init({ } case "Sats": { switch (topSeriesType) { + case null: case CANDLE: { series = chart.addCandlestickSeries({ vecId: "ohlc_in_sats", @@ -381,6 +385,7 @@ export function init({ setDataCallback: printLatest, options: { priceLineVisible: true, + lastValueVisible: true, }, order: 0, }); @@ -395,7 +400,6 @@ export function init({ seriesListTop[0]?.remove(); seriesListTop[0] = series; - // setDataCallback insimport("./options").tead of hasData signals.createEffect( () => ({ latest: webSockets.kraken1dCandle.latest(), diff --git a/websites/bitview/scripts/main.js b/websites/bitview/scripts/main.js index bd3830bc1..e2d64baa6 100644 --- a/websites/bitview/scripts/main.js +++ b/websites/bitview/scripts/main.js @@ -6,7 +6,7 @@ * @import * as _ from "../packages/leeoniya-ufuzzy/1.0.19/dist/uFuzzy.d.ts" * @import { SerializedChartableIndex } from "./chart"; * @import { Signal, Signals, Accessor } from "../packages/solidjs-signals/wrapper"; - * @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" + * @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, EmptyAddressIndex, LoadedAddressIndex } from "./vecid-to-indexes" */ /** @@ -50,6 +50,8 @@ * "%pnl" | * "constant" | * "vB" | + * "block" | + * "address data" | * "sd" | * "Epoch" | * "Height" | @@ -721,12 +723,25 @@ function createUtils() { /** @type {Unit | undefined} */ let unit; + /** + + * @param {Unit} u + */ + function setUnit(u) { + if (unit) + throw Error( + `Can't assign "${u}" to unit, "${unit}" is already assigned to "${id}"`, + ); + unit = u; + } + if ( (!unit || thoroughUnitCheck) && (id.includes("in_sats") || (id.endsWith("supply") && !(id.endsWith("circulating_supply") || id.endsWith("_own_supply"))) || - id.endsWith("supply_even") || + id.endsWith("supply_half") || + id.endsWith("supply_breakeven") || id.endsWith("supply_in_profit") || id.endsWith("supply_in_loss") || id.endsWith("stack") || @@ -743,43 +758,50 @@ function createUtils() { id.endsWith("dominance") ))) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Sats"; + setUnit("Sats"); } if ((!unit || thoroughUnitCheck) && id.includes("in_btc")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "BTC"; + setUnit("BTC"); + } + if ((!unit || thoroughUnitCheck) && id === "chain") { + setUnit("block"); } if ( (!unit || thoroughUnitCheck) && - (id === "high" || - id === "ohlc" || - id === "low" || - id === "close" || - id === "open" || + (id === "emptyaddressdata" || id === "loadedaddressdata") + ) { + setUnit("address data"); + } + if ( + (!unit || thoroughUnitCheck) && + (id === "price_high" || + id === "price_ohlc" || + id === "price_low" || + id === "price_close" || + id === "price_open" || + id === "price_ath" || id === "market_cap" || id.includes("_usd") || id.includes("cointime_value") || - id.startsWith("price") || + id.endsWith("_ago") || id.endsWith("price_paid") || - id.endsWith("price") || - (id.endsWith("_cap") && !id.includes("relative_to")) || + id.endsWith("_price") || + (id.endsWith("_cap") && !id.includes("rel_to")) || id.endsWith("value_created") || id.endsWith("value_destroyed") || ((id.includes("realized") || id.includes("true_market_mean")) && !id.includes("ratio") && - !id.includes("relative_to")) || + !id.includes("rel_to")) || ((id.endsWith("sma") || id.includes("sma_x") || id.endsWith("ema")) && !id.includes("ratio") && + !id.includes("sopr") && !id.includes("hash_rate")) || id === "ath") ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "USD"; + setUnit("USD"); } if ((!unit || thoroughUnitCheck) && id.endsWith("cents")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Cents"; + setUnit("Cents"); } if ( ((!unit || thoroughUnitCheck) && @@ -788,33 +810,32 @@ function createUtils() { (id.endsWith("sma") || id.endsWith("ema") || id.endsWith("zscore"))) || + id.includes("sopr") || id.endsWith("_5sd") || id.endsWith("1sd") || id.endsWith("2sd") || id.endsWith("3sd") || - id.endsWith("p1") || - id.endsWith("p2") || - id.endsWith("p5") || - id.endsWith("p95") || - id.endsWith("p98") || - id.endsWith("p99"))) || + id.endsWith("pct1") || + id.endsWith("pct2") || + id.endsWith("pct5") || + id.endsWith("pct95") || + id.endsWith("pct98") || + id.endsWith("pct99"))) || id.includes("liveliness") || id.includes("vaultedness") || id == "puell_multiple" ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Ratio"; + setUnit("Ratio"); } if ( (!unit || thoroughUnitCheck) && - (id === "drawdown" || + (id === "price_drawdown" || id.endsWith("oscillator") || id.endsWith("dominance") || id.endsWith("returns") || id.endsWith("cagr")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "percentage"; + setUnit("percentage"); } if ( (!unit || thoroughUnitCheck) && @@ -823,43 +844,35 @@ function createUtils() { id.startsWith("block_count") || (id.includes("tx_v") && !id.includes("vsize"))) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Count"; + setUnit("Count"); } if ( (!unit || thoroughUnitCheck) && (id.startsWith("hash_rate") || id.endsWith("as_hash")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "H/s"; + setUnit("H/s"); } if ((!unit || thoroughUnitCheck) && id.includes("fee_rate")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "sat/vB"; + setUnit("sat/vB"); } if ((!unit || thoroughUnitCheck) && id.startsWith("is_")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Bool"; + setUnit("Bool"); } if ((!unit || thoroughUnitCheck) && id.endsWith("type")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Type"; + setUnit("Type"); } if ( (!unit || thoroughUnitCheck) && (id === "interval" || id.startsWith("block_interval")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "secs"; + setUnit("secs"); } if ((!unit || thoroughUnitCheck) && id.endsWith("locktime")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Locktime"; + setUnit("Locktime"); } if ((!unit || thoroughUnitCheck) && id.endsWith("version")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Version"; + setUnit("Version"); } if ( (!unit || thoroughUnitCheck) && @@ -869,132 +882,101 @@ function createUtils() { id.endsWith("total_size") || id.includes("block_size")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Bytes"; + setUnit("Bytes"); } if ((!unit || thoroughUnitCheck) && id.endsWith("_sd")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "sd"; + setUnit("sd"); } if ( (!unit || thoroughUnitCheck) && (id.includes("vsize") || id.includes("vbytes")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "vB"; + setUnit("vB"); } if ((!unit || thoroughUnitCheck) && id.includes("weight")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "WU"; + setUnit("WU"); } if ((!unit || thoroughUnitCheck) && id.endsWith("index")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Index"; + setUnit("Index"); } if ( (!unit || thoroughUnitCheck) && (id === "date" || id === "date_fixed") ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Date"; + setUnit("Date"); } if ( (!unit || thoroughUnitCheck) && (id === "timestamp" || id === "timestamp_fixed") ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Timestamp"; + setUnit("Timestamp"); } if ((!unit || thoroughUnitCheck) && id.includes("coinblocks")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "coinblocks"; + setUnit("coinblocks"); } if ((!unit || thoroughUnitCheck) && id.includes("coindays")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "coindays"; + setUnit("coindays"); } if ((!unit || thoroughUnitCheck) && id.includes("satblocks")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "satblocks"; + setUnit("satblocks"); } if ((!unit || thoroughUnitCheck) && id.includes("satdays")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "satdays"; + setUnit("satdays"); } if ((!unit || thoroughUnitCheck) && id.endsWith("height")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Height"; + setUnit("Height"); } - if ((!unit || thoroughUnitCheck) && id.endsWith("relative_to_market_cap")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%mcap"; + if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_market_cap")) { + setUnit("%mcap"); + } + if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_own_market_cap")) { + setUnit("%cmcap"); } if ( (!unit || thoroughUnitCheck) && - id.endsWith("relative_to_own_market_cap") + id.endsWith("rel_to_own_unrealized_total_pnl") ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%cmcap"; + setUnit("%cp+l"); + } + if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_realized_cap")) { + setUnit("%rcap"); } if ( (!unit || thoroughUnitCheck) && - id.endsWith("relative_to_own_unrealized_profit_plus_loss") + id.endsWith("rel_to_circulating_supply") ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%cp+l"; + setUnit("%all"); } if ( (!unit || thoroughUnitCheck) && - id.endsWith("relative_to_realized_cap") + (id.includes("rel_to_realized_profit") || + id.includes("rel_to_realized_loss")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%rcap"; + setUnit("%pnl"); } - if ( - (!unit || thoroughUnitCheck) && - id.endsWith("relative_to_circulating_supply") - ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%all"; - } - if ( - (!unit || thoroughUnitCheck) && - (id.includes("relative_to_realized_profit") || - id.includes("relative_to_realized_loss")) - ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%pnl"; - } - if ((!unit || thoroughUnitCheck) && id.endsWith("relative_to_own_supply")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "%self"; + if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_own_supply")) { + setUnit("%self"); } if ((!unit || thoroughUnitCheck) && id.endsWith("epoch")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Epoch"; + setUnit("Epoch"); } if ((!unit || thoroughUnitCheck) && id === "difficulty") { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Difficulty"; + setUnit("Difficulty"); } if ((!unit || thoroughUnitCheck) && id === "blockhash") { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Hash"; + setUnit("Hash"); } if ( (!unit || thoroughUnitCheck) && (id.includes("days_between") || id.includes("days_since")) ) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Days"; + setUnit("Days"); } if ((!unit || thoroughUnitCheck) && id.includes("years_between")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "Years"; + setUnit("Years"); } if ((!unit || thoroughUnitCheck) && id.startsWith("constant")) { - if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`); - unit = "constant"; + setUnit("constant"); } if (!unit) { @@ -1205,6 +1187,10 @@ function createUtils() { return "weekindex"; case /** @satisfies {YearIndex} */ (24): return "yearindex"; + case /** @satisfies {LoadedAddressIndex} */ (25): + return "loadedaddressindex"; + case /** @satisfies {EmptyAddressIndex} */ (26): + return "emptyaddressindex"; } }, }, diff --git a/websites/bitview/scripts/options.js b/websites/bitview/scripts/options.js index 6d99b6fdb..adea4a10f 100644 --- a/websites/bitview/scripts/options.js +++ b/websites/bitview/scripts/options.js @@ -94,6 +94,7 @@ * @typedef {Object} PartialUrlOptionSpecific * @property {"url"} [kind] * @property {() => string} url + * @property {string} title * @property {boolean} [qrcode] * * @typedef {PartialOption & PartialUrlOptionSpecific} PartialUrlOption @@ -152,7 +153,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { /** * @typedef {"cumulative_"} CumulativePrefix - * @typedef {"_30d_change"} _30DChageSubString + * @typedef {"_30d_delta"} _30DChageSubString * @typedef {StartsWith} CumulativeVecId * @typedef {ExcludeSubstring, _30DChageSubString>} CumulativeVecIdBase * @typedef {"_avg"} AverageSuffix @@ -214,13 +215,13 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { const terms = /** @type {const} */ ([ { - key: "short_term_holders", + key: "sth", name: "short", title: "Short Term Holders", color: colors.yellow, }, { - key: "long_term_holders", + key: "lth", name: "long", title: "Long Term Holders", color: colors.fuchsia, @@ -1205,7 +1206,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { */ function createCumulativeSeries({ concat, title = "", color }) { return /** @satisfies {AnyFetchedSeriesBlueprint} */ ({ - key: `${concat}_cum`, + key: `${concat}_cumulative`, title: `Cumulative ${title}`, color: color ?? colors.cyan, defaultActive: false, @@ -1302,23 +1303,6 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ]; } - /** - * @param {Object} args - * @param {VecId & CumulativeVecIdBase} args.key - * @param {string} args.name - */ - function createBaseSumCumulativeSeries({ key, name }) { - return [ - createBaseSeries({ - key, - name, - }), - ...createSumCumulativeSeries({ - concat: key, - }), - ]; - } - /** * @typedef {"_ratio_zscore"} RatioZScoreCapSuffix * @typedef {EndsWith} VecIdRatioZScoreCap @@ -1337,27 +1321,27 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { function createPriceWithRatioOptions({ name, title, legend, key, color }) { const percentiles = [ { - name: "p1", + name: "pct1", color: colors.indigo, }, { - name: "p2", + name: "pct2", color: colors.violet, }, { - name: "p5", + name: "pct5", color: colors.purple, }, { - name: "p95", + name: "pct95", color: colors.amber, }, { - name: "p98", + name: "pct98", color: colors.orange, }, { - name: "p99", + name: "pct99", color: colors.red, }, ]; @@ -1416,10 +1400,10 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { name: legend, color, }), - ...(`${key}_ratio_p1sd_as_price` in vecIdToIndexes + ...(`${key}_ratio_p1sd_in_usd` in vecIdToIndexes ? percentiles.map(({ name, color }) => createBaseSeries({ - key: `${key}_ratio_${name}_as_price`, + key: `${key}_ratio_${name}_in_usd`, name, color, defaultActive: false, @@ -1486,25 +1470,25 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color, }), createBaseSeries({ - key: `${key}_ratio_1y_0sd_as_price`, + key: `${key}_ratio_1y_0sd_in_usd`, name: "1y 0sd", color: colors.fuchsia, defaultActive: false, }), createBaseSeries({ - key: `${key}_ratio_2y_0sd_as_price`, + key: `${key}_ratio_2y_0sd_in_usd`, name: "2y 0sd", color: colors.purple, defaultActive: false, }), createBaseSeries({ - key: `${key}_ratio_4y_0sd_as_price`, + key: `${key}_ratio_4y_0sd_in_usd`, name: "4y 0sd", color: colors.violet, defaultActive: false, }), createBaseSeries({ - key: `${key}_ratio_0sd_as_price`, + key: `${key}_ratio_0sd_in_usd`, name: "0sd", color: colors.indigo, defaultActive: false, @@ -1634,7 +1618,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }, ].map(({ sdKey, name, color }) => createBaseSeries({ - key: `${key}_ratio_${keyAddon}${sdKey}_as_price`, + key: `${key}_ratio_${keyAddon}${sdKey}_in_usd`, name, color, defaultActive: false, @@ -1732,14 +1716,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...(key ? [ createBaseSeries({ - key: `${key}supply_relative_to_circulating_supply`, + key: `${key}supply_rel_to_circulating_supply`, name: "Supply", color: colors.default, }), ] : []), createBaseSeries({ - key: `${key}halved_supply`, + key: `${key}supply_half`, name: "Halved", color: colors.gray, options: { @@ -1777,22 +1761,22 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color: colors.red, }), createBaseSeries({ - key: `${key}supply_even`, + key: `${key}supply_breakeven`, name: useGroupName ? name : "Even", color: colors.yellow, }), createBaseSeries({ - key: `${key}supply_even_in_btc`, + key: `${key}supply_breakeven_in_btc`, name: useGroupName ? name : "Even", color: colors.yellow, }), createBaseSeries({ - key: `${key}supply_even_in_usd`, + key: `${key}supply_breakeven_in_usd`, name: useGroupName ? name : "Even", color: colors.yellow, }), createBaseSeries({ - key: `${key}halved_supply_in_btc`, + key: `${key}supply_half_in_btc`, name: useGroupName ? name : "Halved", color: "list" in args ? color : colors.gray, options: { @@ -1800,7 +1784,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }, }), createBaseSeries({ - key: `${key}halved_supply_in_usd`, + key: `${key}supply_half_in_usd`, name: useGroupName ? name : "Halved", color: "list" in args ? color : colors.gray, options: { @@ -1810,34 +1794,34 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...(key ? [ createBaseSeries({ - key: `${key}supply_in_profit_relative_to_circulating_supply`, + key: `${key}supply_in_profit_rel_to_circulating_supply`, name: "In Profit", color: colors.green, }), createBaseSeries({ - key: `${key}supply_in_loss_relative_to_circulating_supply`, + key: `${key}supply_in_loss_rel_to_circulating_supply`, name: "In Loss", color: colors.red, }), createBaseSeries({ - key: `${key}supply_even_relative_to_circulating_supply`, + key: `${key}supply_breakeven_rel_to_circulating_supply`, name: "Even", color: colors.yellow, }), ] : []), createBaseSeries({ - key: `${key}supply_in_profit_relative_to_own_supply`, + key: `${key}supply_in_profit_rel_to_own_supply`, name: "In Profit", color: colors.green, }), createBaseSeries({ - key: `${key}supply_in_loss_relative_to_own_supply`, + key: `${key}supply_in_loss_rel_to_own_supply`, name: "In Loss", color: colors.red, }), createBaseSeries({ - key: `${key}supply_even_relative_to_own_supply`, + key: `${key}supply_breakeven_rel_to_own_supply`, name: "Even", color: colors.yellow, }), @@ -1881,7 +1865,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...(key ? [ createBaseSeries({ - key: `${key}supply_relative_to_circulating_supply`, + key: `${key}supply_rel_to_circulating_supply`, name, color, }), @@ -1914,14 +1898,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...(key ? [ createBaseSeries({ - key: `${key}supply_in_profit_relative_to_circulating_supply`, + key: `${key}supply_in_profit_rel_to_circulating_supply`, name, color, }), ] : []), createBaseSeries({ - key: `${key}supply_in_profit_relative_to_own_supply`, + key: `${key}supply_in_profit_rel_to_own_supply`, name, color, }), @@ -1952,14 +1936,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...(key ? [ createBaseSeries({ - key: `${key}supply_in_loss_relative_to_circulating_supply`, + key: `${key}supply_in_loss_rel_to_circulating_supply`, name, color, }), ] : []), createBaseSeries({ - key: `${key}supply_in_loss_relative_to_own_supply`, + key: `${key}supply_in_loss_rel_to_own_supply`, name, color, }), @@ -1973,31 +1957,31 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { const key = fixKey(_key); return /** @type {const} */ ([ createBaseSeries({ - key: `${key}supply_even`, + key: `${key}supply_breakeven`, name, color, }), createBaseSeries({ - key: `${key}supply_even_in_btc`, + key: `${key}supply_breakeven_in_btc`, name, color, }), createBaseSeries({ - key: `${key}supply_even_in_usd`, + key: `${key}supply_breakeven_in_usd`, name, color, }), ...(key ? [ createBaseSeries({ - key: `${key}supply_even_relative_to_circulating_supply`, + key: `${key}supply_breakeven_rel_to_circulating_supply`, name, color, }), ] : []), createBaseSeries({ - key: `${key}supply_even_relative_to_own_supply`, + key: `${key}supply_breakeven_rel_to_own_supply`, name, color, }), @@ -2021,12 +2005,11 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }), }, ...(list.filter( - ({ key }) => `${fixKey(key)}address_count` in vecIdToIndexes, + ({ key }) => `${fixKey(key)}addr_count` in vecIdToIndexes, ).length ? !("list" in args) || list.filter( - ({ key }) => - `${fixKey(key)}empty_address_count` in vecIdToIndexes, + ({ key }) => `${fixKey(key)}empty_addr_count` in vecIdToIndexes, ).length == 0 ? [ { @@ -2035,19 +2018,19 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { bottom: list.flatMap(({ name, color, key: _key }) => { const key = fixKey(_key); return [ - ...(`${key}address_count` in vecIdToIndexes + ...(`${key}addr_count` in vecIdToIndexes ? /** @type {const} */ ([ createBaseSeries({ - key: `${key}address_count`, + key: `${key}addr_count`, name: useGroupName ? name : "Loaded", color: useGroupName ? color : colors.orange, }), ]) : []), - ...(`${key}empty_address_count` in vecIdToIndexes + ...(`${key}empty_addr_count` in vecIdToIndexes ? /** @type {const} */ ([ createBaseSeries({ - key: `${key}empty_address_count`, + key: `${key}empty_addr_count`, name: "Empty", color: colors.gray, defaultActive: false, @@ -2068,13 +2051,13 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { bottom: list .filter( ({ key }) => - `${fixKey(key)}address_count` in vecIdToIndexes, + `${fixKey(key)}addr_count` in vecIdToIndexes, ) .flatMap(({ name, color, key: _key }) => { const key = fixKey(_key); return [ createBaseSeries({ - key: `${key}address_count`, + key: `${key}addr_count`, name, color, }), @@ -2083,7 +2066,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }, ...(list.filter( ({ key }) => - `${fixKey(key)}empty_address_count` in vecIdToIndexes, + `${fixKey(key)}empty_addr_count` in vecIdToIndexes, ).length ? [ { @@ -2092,14 +2075,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { bottom: list .filter( ({ key }) => - `${fixKey(key)}empty_address_count` in + `${fixKey(key)}empty_addr_count` in vecIdToIndexes, ) .flatMap(({ name, color, key: _key }) => { const key = fixKey(_key); return [ createBaseSeries({ - key: `${key}empty_address_count`, + key: `${key}empty_addr_count`, name, color, }), @@ -2151,7 +2134,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${key}realized_cap_30d_change`, + key: `${key}realized_cap_30d_delta`, title: "30d change", defaultActive: false, }), @@ -2161,6 +2144,23 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }), ] : []), + ...(`${key}realized_cap_rel_to_own_market_cap` in + vecIdToIndexes + ? [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + type: "Baseline", + key: `${key}realized_cap_rel_to_own_market_cap`, + title: "ratio", + options: { baseValue: { price: 100 } }, + colors: [colors.red, colors.green], + }), + createPriceLine({ + unit: "%cmcap", + defaultActive: true, + number: 100, + }), + ] + : []), ]); }), }, @@ -2176,7 +2176,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color: colors.green, }), createBaseSeries({ - key: `${fixKey(args.key)}realized_profit_cum`, + key: `${fixKey(args.key)}realized_profit_cumulative`, name: "Cumulative Profit", color: colors.green, defaultActive: false, @@ -2188,18 +2188,18 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { defaultActive: false, }), createBaseSeries({ - key: `${fixKey(args.key)}realized_loss_cum`, + key: `${fixKey(args.key)}realized_loss_cumulative`, name: "Cumulative Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - key: `${fixKey(args.key)}negative_realized_loss`, + key: `${fixKey(args.key)}neg_realized_loss`, name: "Negative Loss", color: colors.red, }), createBaseSeries({ - key: `${fixKey(args.key)}negative_realized_loss_cum`, + key: `${fixKey(args.key)}neg_realized_loss_cumulative`, name: "Cumulative Negative Loss", color: colors.red, defaultActive: false, @@ -2208,7 +2208,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( args.key, - )}realized_profit_relative_to_realized_cap`, + )}realized_profit_rel_to_realized_cap`, title: "Profit", color: colors.green, }), @@ -2216,7 +2216,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( args.key, - )}realized_loss_relative_to_realized_cap`, + )}realized_loss_rel_to_realized_cap`, title: "Loss", color: colors.red, }), @@ -2235,12 +2235,12 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { bottom: list.flatMap(({ color, name, key }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey(key)}net_realized_profit_and_loss`, + key: `${fixKey(key)}net_realized_pnl`, title: "Raw", }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey(key)}net_realized_profit_and_loss_cum`, + key: `${fixKey(key)}net_realized_pnl_cumulative`, title: "Cumulative", defaultActive: false, }), @@ -2248,7 +2248,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_cumulative_30d_change`, + )}net_realized_pnl_cumulative_30d_delta`, title: "cumulative 30d change", defaultActive: false, }), @@ -2256,14 +2256,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_relative_to_realized_cap`, + )}net_realized_pnl_rel_to_realized_cap`, title: "Raw", }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap`, + )}net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap`, title: "cumulative 30d change", defaultActive: false, }), @@ -2271,7 +2271,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap`, + )}net_realized_pnl_cumulative_30d_delta_rel_to_market_cap`, title: "cumulative 30d change", }), createPriceLine({ @@ -2289,8 +2289,8 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { name: "sopr", title: `Spent Output Profit Ratio ${title}`, bottom: list.flatMap(({ color, name, key }) => { - const soprKey = `${fixKey(key)}spent_output_profit_ratio`; - const asoprKey = `${fixKey(key)}adjusted_spent_output_profit_ratio`; + const soprKey = `${fixKey(key)}sopr`; + const asoprKey = `${fixKey(key)}adjusted_sopr`; return [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", @@ -2397,7 +2397,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${key}realized_profit_relative_to_realized_cap`, + key: `${key}realized_profit_rel_to_realized_cap`, title: name, color, }), @@ -2422,7 +2422,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${key}realized_loss_relative_to_realized_cap`, + key: `${key}realized_loss_rel_to_realized_cap`, title: name, color, }), @@ -2440,7 +2440,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...list.flatMap(({ color, name, key }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey(key)}net_realized_profit_and_loss`, + key: `${fixKey(key)}net_realized_pnl`, title: name, color, }), @@ -2448,7 +2448,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_relative_to_realized_cap`, + )}net_realized_pnl_rel_to_realized_cap`, title: name, color, }), @@ -2471,7 +2471,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { const key = fixKey(_key); return /** @type {const} */ ([ createBaseSeries({ - key: `${key}realized_profit_cum`, + key: `${key}realized_profit_cumulative`, name, color, }), @@ -2485,7 +2485,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { const key = fixKey(_key); return /** @type {const} */ ([ createBaseSeries({ - key: `${key}realized_loss_cum`, + key: `${key}realized_loss_cumulative`, name, color, }), @@ -2499,9 +2499,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...list.flatMap(({ color, name, key }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey( - key, - )}net_realized_profit_and_loss_cum`, + key: `${fixKey(key)}net_realized_pnl_cumulative`, title: name, color, defaultActive: false, @@ -2521,7 +2519,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_cumulative_30d_change`, + )}net_realized_pnl_cumulative_30d_delta`, title: name, color, }), @@ -2529,7 +2527,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap`, + )}net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap`, title: name, color, }), @@ -2537,7 +2535,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { type: "Baseline", key: `${fixKey( key, - )}net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap`, + )}net_realized_pnl_cumulative_30d_delta_rel_to_market_cap`, title: name, color, }), @@ -2565,7 +2563,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...list.flatMap(({ color, name, key }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey(key)}spent_output_profit_ratio`, + key: `${fixKey(key)}sopr`, title: name, color, }), @@ -2581,9 +2579,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { .map(({ color, name, key }) => ({ color, name, - key: `${fixKey( - key, - )}adjusted_spent_output_profit_ratio`, + key: `${fixKey(key)}adjusted_sopr`, })) .filter(({ key }) => key in vecIdToIndexes); @@ -2659,7 +2655,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { title: `Unrealized Profit And Loss ${title}`, bottom: [ createBaseSeries({ - key: `${fixKey(args.key)}unrealized_profit_plus_loss`, + key: `${fixKey(args.key)}unrealized_total_pnl`, name: "profit+loss", color: colors.default, }), @@ -2675,42 +2671,42 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { defaultActive: false, }), createBaseSeries({ - key: `${fixKey(args.key)}negative_unrealized_loss`, + key: `${fixKey(args.key)}neg_unrealized_loss`, name: "Negative Loss", color: colors.red, }), createBaseSeries({ - key: `${fixKey(args.key)}unrealized_profit_relative_to_market_cap`, + key: `${fixKey(args.key)}unrealized_profit_rel_to_market_cap`, name: "Profit", color: colors.green, }), createBaseSeries({ - key: `${fixKey(args.key)}unrealized_loss_relative_to_market_cap`, + key: `${fixKey(args.key)}unrealized_loss_rel_to_market_cap`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - key: `${fixKey(args.key)}negative_unrealized_loss_relative_to_market_cap`, + key: `${fixKey(args.key)}neg_unrealized_loss_rel_to_market_cap`, name: "Negative Loss", color: colors.red, }), - ...(`${fixKey(args.key)}unrealized_profit_relative_to_own_market_cap` in + ...(`${fixKey(args.key)}unrealized_profit_rel_to_own_market_cap` in vecIdToIndexes ? [ createBaseSeries({ - key: `${fixKey(args.key)}unrealized_profit_relative_to_own_market_cap`, + key: `${fixKey(args.key)}unrealized_profit_rel_to_own_market_cap`, name: "Profit", color: colors.green, }), createBaseSeries({ - key: `${fixKey(args.key)}unrealized_loss_relative_to_own_market_cap`, + key: `${fixKey(args.key)}unrealized_loss_rel_to_own_market_cap`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - key: `${fixKey(args.key)}negative_unrealized_loss_relative_to_own_market_cap`, + key: `${fixKey(args.key)}neg_unrealized_loss_rel_to_own_market_cap`, name: "Negative Loss", color: colors.red, }), @@ -2723,22 +2719,22 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }), ] : []), - ...(`${fixKey(args.key)}unrealized_profit_relative_to_own_unrealized_profit_plus_loss` in + ...(`${fixKey(args.key)}unrealized_profit_rel_to_own_unrealized_total_pnl` in vecIdToIndexes ? [ createBaseSeries({ - key: `${fixKey(args.key)}unrealized_profit_relative_to_own_unrealized_profit_plus_loss`, + key: `${fixKey(args.key)}unrealized_profit_rel_to_own_unrealized_total_pnl`, name: "Profit", color: colors.green, }), createBaseSeries({ - key: `${fixKey(args.key)}unrealized_loss_relative_to_own_unrealized_profit_plus_loss`, + key: `${fixKey(args.key)}unrealized_loss_rel_to_own_unrealized_total_pnl`, name: "Loss", color: colors.red, defaultActive: false, }), createBaseSeries({ - key: `${fixKey(args.key)}negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss`, + key: `${fixKey(args.key)}neg_unrealized_loss_rel_to_own_unrealized_total_pnl`, name: "Negative Loss", color: colors.red, }), @@ -2799,26 +2795,24 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...list.flatMap(({ color, name, key }) => [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey(key)}net_unrealized_profit_and_loss`, + key: `${fixKey(key)}net_unrealized_pnl`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, }), /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", - key: `${fixKey( - key, - )}net_unrealized_profit_and_loss_relative_to_market_cap`, + key: `${fixKey(key)}net_unrealized_pnl_rel_to_market_cap`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, }), - ...(`${fixKey(key)}net_unrealized_profit_and_loss_relative_to_own_market_cap` in + ...(`${fixKey(key)}net_unrealized_pnl_rel_to_own_market_cap` in vecIdToIndexes ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", key: `${fixKey( key, - )}net_unrealized_profit_and_loss_relative_to_own_market_cap`, + )}net_unrealized_pnl_rel_to_own_market_cap`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, }), @@ -2827,14 +2821,14 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }), ] : []), - ...(`${fixKey(key)}net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss` in + ...(`${fixKey(key)}net_unrealized_pnl_rel_to_own_unrealized_total_pnl` in vecIdToIndexes ? [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ type: "Baseline", key: `${fixKey( key, - )}net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss`, + )}net_unrealized_pnl_rel_to_own_unrealized_total_pnl`, title: useGroupName ? name : "Net", color: useGroupName ? color : undefined, }), @@ -2941,7 +2935,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color, }), createBaseSeries({ - key: `${key}coinblocks_destroyed_cum`, + key: `${key}coinblocks_destroyed_cumulative`, name: useGroupName ? name : "cumulative", color, defaultActive: false, @@ -2952,7 +2946,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color, }), createBaseSeries({ - key: `${key}coindays_destroyed_cum`, + key: `${key}coindays_destroyed_cumulative`, name: useGroupName ? name : "cumulative", color, defaultActive: false, @@ -2977,13 +2971,13 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { { name: "Charts", tree: [ - { - name: "Price", - title: "Bitcoin Price", - }, { name: "Market", tree: [ + { + name: "Price", + title: "Bitcoin Price", + }, { name: "Capitalization", title: "Market Capitalization", @@ -3002,27 +2996,27 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { // name: "Value", top: [ createBaseSeries({ - key: "ath", + key: "price_ath", name: "ath", }), ], bottom: [ createBaseSeries({ - key: "drawdown", + key: "price_drawdown", name: "Drawdown", color: colors.red, }), createBaseSeries({ - key: "days_since_ath", + key: "days_since_price_ath", name: "since", }), createBaseSeries({ - key: "max_days_between_aths", + key: "max_days_between_price_aths", name: "Max", color: colors.red, }), createBaseSeries({ - key: "max_years_between_aths", + key: "max_years_between_price_aths", name: "Max", color: colors.red, }), @@ -3047,7 +3041,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { title: `Market Price ${nameAddon} Moving Averages`, top: averages.map(({ days, key, name, color }) => createBaseSeries({ - key: `${key}_${keyAddon}`, + key: `price_${key}_${keyAddon}`, name: key, color, }), @@ -3056,7 +3050,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { ...averages.map(({ key, name, color }) => ({ name, tree: createPriceWithRatioOptions({ - key: `${key}_${keyAddon}`, + key: `price_${key}_${keyAddon}`, name, title: `${name} Market Price ${nameAddon} Moving Average`, legend: "average", @@ -3087,7 +3081,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { title: `${name} Performance`, bottom: [ /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_returns`, + key: `${key}_price_returns`, title: "Returns", type: "Baseline", }), @@ -3117,17 +3111,17 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { title: "Mayer multiple", top: [ createBaseSeries({ - key: `200d_sma`, + key: `price_200d_sma`, name: "200d sma", color: colors.yellow, }), createBaseSeries({ - key: `200d_sma_x2_4`, + key: `price_200d_sma_x2_4`, name: "200d sma x2.4", color: colors.green, }), createBaseSeries({ - key: `200d_sma_x0_8`, + key: `price_200d_sma_x0_8`, name: "200d sma x0.8", color: colors.red, }), @@ -3135,521 +3129,596 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }, ], }, + { + name: "Investing", + tree: [ + { + name: "DCA vs Lump sum", + tree: [ + .../** @type {const} */ ([ + { name: "1 Week", key: "1w" }, + { name: "1 Month", key: "1m" }, + { name: "3 Month", key: "3m" }, + { name: "6 Month", key: "6m" }, + { name: "1 Year", key: "1y" }, + ]).map( + ({ name, key }) => + /** @satisfies {PartialChartOption} */ ({ + name, + title: `${name} DCA vs Lump Sum Returns`, + top: [ + createBaseSeries({ + key: `${key}_dca_avg_price`, + name: `dca`, + color: colors.orange, + }), + createBaseSeries({ + key: `price_${key}_ago`, + name: `lump sum`, + color: colors.cyan, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}_dca_returns`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}_price_returns`, + title: "lump sum", + type: "Baseline", + }), + createPriceLine({ + unit: "percentage", + }), + ], + }), + ), + .../** @type {const} */ ([ + { name: "2 Year", key: "2y" }, + { name: "3 Year", key: "3y" }, + { name: "4 Year", key: "4y" }, + { name: "5 Year", key: "5y" }, + { name: "6 Year", key: "6y" }, + { name: "8 Year", key: "8y" }, + { name: "10 Year", key: "10y" }, + ]).map( + ({ name, key }) => + /** @satisfies {PartialChartOption} */ ({ + name, + title: `${name} DCA vs Lump Sum Returns`, + top: [ + createBaseSeries({ + key: `${key}_dca_avg_price`, + name: `dca`, + color: colors.orange, + }), + createBaseSeries({ + key: `price_${key}_ago`, + name: `lump sum`, + color: colors.cyan, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}_dca_returns`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}_price_returns`, + title: "lump sum", + type: "Baseline", + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}_dca_cagr`, + title: "dca cagr", + type: "Baseline", + colors: [colors.yellow, colors.pink], + defaultActive: false, + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}_cagr`, + title: "lump sum cagr", + type: "Baseline", + defaultActive: false, + }), + createPriceLine({ + unit: "percentage", + }), + ], + }), + ), + ], + }, + { + name: "DCA Class", + tree: [ + { + name: "Compare", + title: "DCA Classes", + top: dcaClasses.map(({ year, color, defaultActive }) => + createBaseSeries({ + key: `dca_class_${year}_avg_price`, + name: `${year}`, + color, + defaultActive, + }), + ), + }, + ...dcaClasses.map( + ({ year, color }) => + /** @satisfies {PartialChartOption} */ ({ + name: `${year}`, + title: `DCA Since ${year}`, + top: [ + createBaseSeries({ + key: `dca_class_${year}_avg_price`, + name: "cost basis", + color, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `dca_class_${year}_returns`, + title: "dca", + type: "Baseline", + }), + createPriceLine({ + unit: "percentage", + }), + ], + }), + ), + ], + }, + ], + }, ], }, { - name: "Investing", + name: "Chain", tree: [ { - name: "DCA vs Lump sum", + name: "Block", tree: [ - .../** @type {const} */ ([ - { name: "1 Week", key: "1w" }, - { name: "1 Month", key: "1m" }, - { name: "3 Month", key: "3m" }, - { name: "6 Month", key: "6m" }, - { name: "1 Year", key: "1y" }, - ]).map( - ({ name, key }) => - /** @satisfies {PartialChartOption} */ ({ - name, - title: `${name} DCA vs Lump Sum Returns`, - top: [ - createBaseSeries({ - key: `${key}_dca_avg_price`, - name: `dca`, - color: colors.orange, - }), - createBaseSeries({ - key: `price_${key}_ago`, - name: `lump sum`, - color: colors.cyan, - }), - ], - bottom: [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_dca_returns`, - title: "dca", - type: "Baseline", - colors: [colors.yellow, colors.pink], - }), - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_returns`, - title: "lump sum", - type: "Baseline", - }), - createPriceLine({ - unit: "percentage", - }), - ], + { + name: "Count", + title: "Block Count", + bottom: [ + ...createSumCumulativeSeries({ + concat: "block_count", }), - ), - .../** @type {const} */ ([ - { name: "2 Year", key: "2y" }, - { name: "3 Year", key: "3y" }, - { name: "4 Year", key: "4y" }, - { name: "5 Year", key: "5y" }, - { name: "6 Year", key: "6y" }, - { name: "8 Year", key: "8y" }, - { name: "10 Year", key: "10y" }, - ]).map( - ({ name, key }) => - /** @satisfies {PartialChartOption} */ ({ - name, - title: `${name} DCA vs Lump Sum Returns`, - top: [ - createBaseSeries({ - key: `${key}_dca_avg_price`, - name: `dca`, - color: colors.orange, - }), - createBaseSeries({ - key: `price_${key}_ago`, - name: `lump sum`, - color: colors.cyan, - }), - ], - bottom: [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_dca_returns`, - title: "dca", - type: "Baseline", - colors: [colors.yellow, colors.pink], - }), - - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_returns`, - title: "lump sum", - type: "Baseline", - }), - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_dca_cagr`, - title: "dca cagr", - type: "Baseline", - colors: [colors.yellow, colors.pink], - defaultActive: false, - }), - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `${key}_cagr`, - title: "lump sum cagr", - type: "Baseline", - defaultActive: false, - }), - createPriceLine({ - unit: "percentage", - }), - ], + createPriceLine({ + unit: "Count", + name: "Target", + number: 144, }), - ), + ], + }, + { + name: "Interval", + title: "Block Interval", + bottom: [ + createBaseSeries({ + key: "interval", + name: "Interval", + }), + createAverageSeries({ concat: "block_interval" }), + ...createMinMaxPercentilesSeries({ + concat: "block_interval", + }), + createPriceLine({ + unit: "secs", + name: "Target", + number: 600, + }), + ], + }, + { + name: "Size", + title: "Block Size", + bottom: [ + createBaseSeries({ + key: "total_size", + name: "raw", + }), + createBaseSeries({ + key: "vbytes", + name: "raw", + }), + createBaseSeries({ + key: "weight", + name: "raw", + }), + // createBaseSeries({ + // key: "weight", + // name: "Weight", + // }), + ...createAverageSumCumulativeMinMaxPercentilesSeries( + "block_size", + ), + ...createAverageSumCumulativeMinMaxPercentilesSeries( + "block_weight", + ), + ...createAverageSumCumulativeMinMaxPercentilesSeries( + "block_vbytes", + ), + ], + }, ], }, { - name: "DCA Class", + name: "Transaction", tree: [ { - name: "Compare", - title: "DCA Classes", - top: dcaClasses.map(({ year, color, defaultActive }) => - createBaseSeries({ - key: `dca_class_${year}_avg_price`, - name: `${year}`, - color, - defaultActive, + name: "Count", + title: "Transaction Count", + bottom: createBaseAverageSumCumulativeMinMaxPercentilesSeries( + { + key: "tx_count", + name: "Count", + }, + ), + }, + { + name: "Size", + title: "Transaction Size", + bottom: [ + createAverageSeries({ + concat: "tx_weight", + title: "Weight", + }), + ...createMinMaxPercentilesSeries({ + concat: "tx_weight", + title: "Weight", + }), + createAverageSeries({ concat: "tx_vsize", title: "VSize" }), + ...createMinMaxPercentilesSeries({ + concat: "tx_vsize", + title: "VSize", + }), + ], + }, + { + name: "Versions", + title: "Transaction Versions", + bottom: [ + [colors.orange, colors.red], + [colors.cyan, colors.blue], + [colors.lime, colors.green], + ].flatMap(([sumColor, cumulativeColor], index) => + createSumCumulativeSeries({ + concat: `tx_v${index + 1}`, + common: `v${index + 1}`, + sumColor, + cumulativeColor, }), ), }, - ...dcaClasses.map( - ({ year, color }) => - /** @satisfies {PartialChartOption} */ ({ - name: `${year}`, - title: `DCA Since ${year}`, - top: [ - createBaseSeries({ - key: `dca_class_${year}_avg_price`, - name: "cost basis", - color, - }), - ], - bottom: [ - /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ - key: `dca_class_${year}_returns`, - title: "dca", - type: "Baseline", - }), - createPriceLine({ - unit: "percentage", - }), - ], - }), - ), - ], - }, - ], - }, - { - name: "Mining", - tree: [ - { - name: "Supply", - title: "Circulating Supply", - bottom: [ - createBaseSeries({ - key: "supply", - name: "Mined", - }), - createBaseSeries({ - key: "supply_in_btc", - name: "Mined", - }), - createBaseSeries({ - key: "supply_in_usd", - name: "Mined", - }), ], }, { - name: "Coinbase", - title: "Coinbase", - bottom: [ - ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "coinbase", - name: "Coinbase", - }), - ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "coinbase_in_btc", - name: "Coinbase", - }), - ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "coinbase_in_usd", - name: "Coinbase", - }), - ], - }, - { - name: "Subsidy", - title: "Subsidy", - bottom: [ - ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "subsidy", - name: "Subsidy", - }), - createBaseSeries({ - key: "subsidy_usd_1y_sma", - name: "1y sma", - }), - ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "subsidy_in_btc", - name: "Subsidy", - }), - ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "subsidy_in_usd", - name: "Subsidy", - }), - ], - }, - { - name: "Fee", - title: "Transaction Fee", - bottom: [ - ...createAverageSumCumulativeMinMaxPercentilesSeries("fee"), - ...createAverageSumCumulativeMinMaxPercentilesSeries( - "fee_in_btc", - ), - ...createAverageSumCumulativeMinMaxPercentilesSeries( - "fee_in_usd", - ), - ], - }, - { - name: "Dominance", - title: "Reward Dominance", - bottom: [ - createBaseSeries({ - key: "fee_dominance", - name: "Fee", - color: colors.amber, - }), - createBaseSeries({ - key: "subsidy_dominance", - name: "Subsidy", - color: colors.red, - }), - ], - }, - { - name: "Unclaimed Rewards", - title: "Unclaimed Rewards", - bottom: [ - ...createSumCumulativeSeries({ - concat: "unclaimed_rewards", - }), - ...createSumCumulativeSeries({ - concat: "unclaimed_rewards_in_btc", - }), - ...createSumCumulativeSeries({ - concat: "unclaimed_rewards_in_usd", - }), - ], - }, - { - name: "Feerate", - title: "Transaction Fee Rate", - bottom: [ - createAverageSeries({ concat: "fee_rate" }), - ...createMinMaxPercentilesSeries({ - concat: "fee_rate", - }), - ], - }, - { - name: "Puell multiple", - title: "Puell multiple", - bottom: [ - createBaseSeries({ - key: "puell_multiple", - name: "Multiple", - }), - ], - }, - { - name: "Difficulty", - title: "Difficulty", - bottom: [ - createBaseSeries({ - key: "difficulty", - name: "Value", - }), - createBaseSeries({ - key: "difficultyepoch", - name: "Epoch", - }), - ], - }, - { - name: "hash", + name: "Input", tree: [ { - name: "Rate", - title: "Hash Rate", + name: "Count", + title: "Transaction Input Count", + bottom: [ + createAverageSeries({ concat: "input_count" }), + createCumulativeSeries({ + concat: "input_count", + }), + ...createMinMaxPercentilesSeries({ + concat: "input_count", + }), + ], + }, + // { + // name: "Value", + // title: "Transaction Input Value", + // bottom: [ + // createAverageSeries({ concat: "input_value" }), + // ...createSumCumulativeSeries({ concat: "input_value" }), + // ], + // }, + ], + }, + { + name: "Output", + tree: [ + { + name: "Count", + title: "Transaction Output Count", + bottom: [ + createAverageSeries({ concat: "output_count" }), + createCumulativeSeries({ + concat: "input_count", + }), + ...createMinMaxPercentilesSeries({ + concat: "output_count", + }), + ], + }, + // { + // name: "Value", + // title: "Transaction Output Value", + // bottom: [ + // createAverageSeries({ concat: "output_value" }), + // ...createSumCumulativeSeries({ concat: "output_value" }), + // ], + // }, + ], + }, + { + name: "Mining", + tree: [ + { + name: "Supply", + title: "Circulating Supply", bottom: [ createBaseSeries({ - key: "hash_rate", - name: "Raw", + key: "supply", + name: "Mined", }), createBaseSeries({ - key: "hash_rate_1w_sma", - name: "1w sma", - color: colors.red, - defaultActive: false, + key: "supply_in_btc", + name: "Mined", }), createBaseSeries({ - key: "hash_rate_1m_sma", - name: "1m sma", - color: colors.pink, - defaultActive: false, + key: "supply_in_usd", + name: "Mined", + }), + ], + }, + { + name: "Coinbase", + title: "Coinbase", + bottom: [ + ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ + key: "coinbase", + name: "Coinbase", + }), + ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ + key: "coinbase_in_btc", + name: "Coinbase", + }), + ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ + key: "coinbase_in_usd", + name: "Coinbase", + }), + ], + }, + { + name: "Subsidy", + title: "Subsidy", + bottom: [ + ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ + key: "subsidy", + name: "Subsidy", }), createBaseSeries({ - key: "hash_rate_2m_sma", - name: "2m sma", - color: colors.purple, - defaultActive: false, - }), - createBaseSeries({ - key: "hash_rate_1y_sma", + key: "subsidy_usd_1y_sma", name: "1y sma", - color: colors.indigo, - defaultActive: false, + }), + ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ + key: "subsidy_in_btc", + name: "Subsidy", + }), + ...createBaseAverageSumCumulativeMinMaxPercentilesSeries({ + key: "subsidy_in_usd", + name: "Subsidy", + }), + ], + }, + { + name: "Fee", + title: "Transaction Fee", + bottom: [ + ...createAverageSumCumulativeMinMaxPercentilesSeries("fee"), + ...createAverageSumCumulativeMinMaxPercentilesSeries( + "fee_in_btc", + ), + ...createAverageSumCumulativeMinMaxPercentilesSeries( + "fee_in_usd", + ), + ], + }, + { + name: "Dominance", + title: "Reward Dominance", + bottom: [ + createBaseSeries({ + key: "fee_dominance", + name: "Fee", + color: colors.amber, }), createBaseSeries({ - key: "difficulty_as_hash", - name: "difficulty", - color: colors.default, - options: { - lineStyle: 1, - }, + key: "subsidy_dominance", + name: "Subsidy", + color: colors.red, + }), + ], + }, + { + name: "Unclaimed Rewards", + title: "Unclaimed Rewards", + bottom: [ + ...createSumCumulativeSeries({ + concat: "unclaimed_rewards", + }), + ...createSumCumulativeSeries({ + concat: "unclaimed_rewards_in_btc", + }), + ...createSumCumulativeSeries({ + concat: "unclaimed_rewards_in_usd", + }), + ], + }, + { + name: "Feerate", + title: "Transaction Fee Rate", + bottom: [ + createAverageSeries({ concat: "fee_rate" }), + ...createMinMaxPercentilesSeries({ + concat: "fee_rate", + }), + ], + }, + { + name: "Puell multiple", + title: "Puell multiple", + bottom: [ + createBaseSeries({ + key: "puell_multiple", + name: "Multiple", + }), + ], + }, + { + name: "Difficulty", + title: "Difficulty", + bottom: [ + createBaseSeries({ + key: "difficulty", + name: "Value", + }), + createBaseSeries({ + key: "difficultyepoch", + name: "Epoch", + }), + ], + }, + { + name: "hash", + tree: [ + { + name: "Rate", + title: "Hash Rate", + bottom: [ + createBaseSeries({ + key: "hash_rate", + name: "Raw", + }), + createBaseSeries({ + key: "hash_rate_1w_sma", + name: "1w sma", + color: colors.red, + defaultActive: false, + }), + createBaseSeries({ + key: "hash_rate_1m_sma", + name: "1m sma", + color: colors.pink, + defaultActive: false, + }), + createBaseSeries({ + key: "hash_rate_2m_sma", + name: "2m sma", + color: colors.purple, + defaultActive: false, + }), + createBaseSeries({ + key: "hash_rate_1y_sma", + name: "1y sma", + color: colors.indigo, + defaultActive: false, + }), + createBaseSeries({ + key: "difficulty_as_hash", + name: "difficulty", + color: colors.default, + options: { + lineStyle: 1, + }, + }), + ], + }, + ], + }, + { + name: "Halving Epoch", + title: "Halving Epoch", + bottom: [ + createBaseSeries({ + key: "halvingepoch", + name: "Epoch", }), ], }, ], }, { - name: "Halving Epoch", - title: "Halving Epoch", - bottom: [ - createBaseSeries({ - key: "halvingepoch", - name: "Epoch", - }), + name: "Unspendable", + tree: [ + { + name: "supply", + title: "Unspendable Supply", + bottom: [ + createBaseSeries({ + key: "unspendable_supply", + name: "Supply", + }), + createBaseSeries({ + key: "unspendable_supply_in_btc", + name: "Supply", + }), + createBaseSeries({ + key: "unspendable_supply_in_usd", + name: "Supply", + }), + ], + }, + { + name: "op_return", + tree: [ + { + name: "outputs", + title: "op_return outputs", + bottom: [ + createBaseSeries({ + key: "opreturn_count", + name: "Count", + }), + createBaseSeries({ + key: "opreturn_count", + name: "sum", + }), + createBaseSeries({ + key: "opreturn_count_cumulative", + name: "cumulative", + color: colors.red, + }), + ], + }, + { + name: "supply", + title: "OP_return Supply", + bottom: [ + createBaseSeries({ + key: "opreturn_supply", + name: "Supply", + }), + createBaseSeries({ + key: "opreturn_supply_in_btc", + name: "Supply", + }), + createBaseSeries({ + key: "opreturn_supply_in_usd", + name: "Supply", + }), + ], + }, + ], + }, ], }, ], }, - { - name: "Block", - tree: [ - { - name: "Count", - title: "Block Count", - bottom: [ - ...createSumCumulativeSeries({ - concat: "block_count", - }), - createPriceLine({ - unit: "Count", - name: "Target", - number: 144, - }), - ], - }, - { - name: "Interval", - title: "Block Interval", - bottom: [ - createBaseSeries({ - key: "interval", - name: "Interval", - }), - createAverageSeries({ concat: "block_interval" }), - ...createMinMaxPercentilesSeries({ - concat: "block_interval", - }), - createPriceLine({ - unit: "secs", - name: "Target", - number: 600, - }), - ], - }, - { - name: "Size", - title: "Block Size", - bottom: [ - createBaseSeries({ - key: "total_size", - name: "raw", - }), - createBaseSeries({ - key: "vbytes", - name: "raw", - }), - createBaseSeries({ - key: "weight", - name: "raw", - }), - // createBaseSeries({ - // key: "weight", - // name: "Weight", - // }), - ...createAverageSumCumulativeMinMaxPercentilesSeries( - "block_size", - ), - ...createAverageSumCumulativeMinMaxPercentilesSeries( - "block_weight", - ), - ...createAverageSumCumulativeMinMaxPercentilesSeries( - "block_vbytes", - ), - ], - }, - ], - }, - { - name: "Transaction", - tree: [ - { - name: "Count", - title: "Transaction Count", - bottom: createBaseAverageSumCumulativeMinMaxPercentilesSeries({ - key: "tx_count", - name: "Count", - }), - }, - { - name: "Size", - title: "Transaction Size", - bottom: [ - createAverageSeries({ concat: "tx_weight", title: "Weight" }), - ...createMinMaxPercentilesSeries({ - concat: "tx_weight", - title: "Weight", - }), - createAverageSeries({ concat: "tx_vsize", title: "VSize" }), - ...createMinMaxPercentilesSeries({ - concat: "tx_vsize", - title: "VSize", - }), - ], - }, - { - name: "Versions", - title: "Transaction Versions", - bottom: [ - [colors.orange, colors.red], - [colors.cyan, colors.blue], - [colors.lime, colors.green], - ].flatMap(([sumColor, cumulativeColor], index) => - createSumCumulativeSeries({ - concat: `tx_v${index + 1}`, - common: `v${index + 1}`, - sumColor, - cumulativeColor, - }), - ), - }, - ], - }, - { - name: "Input", - tree: [ - { - name: "Count", - title: "Transaction Input Count", - bottom: [ - createAverageSeries({ concat: "input_count" }), - createCumulativeSeries({ - concat: "input_count", - }), - ...createMinMaxPercentilesSeries({ - concat: "input_count", - }), - ], - }, - // { - // name: "Value", - // title: "Transaction Input Value", - // bottom: [ - // createAverageSeries({ concat: "input_value" }), - // ...createSumCumulativeSeries({ concat: "input_value" }), - // ], - // }, - ], - }, - { - name: "Output", - tree: [ - { - name: "Count", - title: "Transaction Output Count", - bottom: [ - createAverageSeries({ concat: "output_count" }), - createCumulativeSeries({ - concat: "input_count", - }), - ...createMinMaxPercentilesSeries({ - concat: "output_count", - }), - ], - }, - // { - // name: "Value", - // title: "Transaction Output Value", - // bottom: [ - // createAverageSeries({ concat: "output_value" }), - // ...createSumCumulativeSeries({ concat: "output_value" }), - // ], - // }, - ], - }, { name: "Cohorts", tree: [ @@ -3793,68 +3862,6 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { }, ], }, - { - name: "Unspendable", - tree: [ - { - name: "supply", - title: "Unspendable Supply", - bottom: [ - createBaseSeries({ - key: "unspendable_supply", - name: "Supply", - }), - createBaseSeries({ - key: "unspendable_supply_in_btc", - name: "Supply", - }), - createBaseSeries({ - key: "unspendable_supply_in_usd", - name: "Supply", - }), - ], - }, - { - name: "op_return", - tree: [ - { - name: "outputs", - title: "op_return outputs", - bottom: [ - createBaseSeries({ key: "opreturn_count", name: "Count" }), - createBaseSeries({ - key: "opreturn_count", - name: "sum", - }), - createBaseSeries({ - key: "opreturn_count_cum", - name: "cumulative", - color: colors.red, - }), - ], - }, - { - name: "supply", - title: "OP_return Supply", - bottom: [ - createBaseSeries({ - key: "opreturn_supply", - name: "Supply", - }), - createBaseSeries({ - key: "opreturn_supply_in_btc", - name: "Supply", - }), - createBaseSeries({ - key: "opreturn_supply_in_usd", - name: "Supply", - }), - ], - }, - ], - }, - ], - }, { name: "Cointime", tree: [ @@ -4001,7 +4008,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color: colors.red, }), createBaseSeries({ - key: "coinblocks_destroyed_cum", + key: "coinblocks_destroyed_cumulative", name: "Cumulative Destroyed", color: colors.red, defaultActive: false, @@ -4012,7 +4019,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color: colors.orange, }), createBaseSeries({ - key: "coinblocks_created_cum", + key: "coinblocks_created_cumulative", name: "Cumulative created", color: colors.orange, defaultActive: false, @@ -4023,7 +4030,7 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { color: colors.green, }), createBaseSeries({ - key: "coinblocks_stored_cum", + key: "coinblocks_stored_cumulative", name: "Cumulative stored", color: colors.green, defaultActive: false, @@ -4055,19 +4062,23 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { { name: "API", url: () => "/api", + title: "Link to API documentation", }, { name: "MCP", url: () => "https://github.com/bitcoinresearchkit/brk/tree/main/crates/brk_mcp#brk-mcp", + title: "Link to MCP documentation", }, { name: "Crates", - url: () => "https://crates.io/crates/brk", + url: () => "/crates", + title: "Link to BRK on crates.io", }, { name: "Source", - url: () => "https://github.com/bitcoinresearchkit/brk", + url: () => "/github", + title: "Link to BRK's repository", }, ], }, @@ -4076,16 +4087,18 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { tree: [ { name: "Status", - url: () => "https://status.bitview.space/", + url: () => "/status", + title: "Link to servers status", }, { name: "Self", - url: () => "https://crates.io/crates/brk_cli", + url: () => "/cli", + title: "Link to self-hosting documentation", }, { name: "As a service", - url: () => - "https://github.com/bitcoinresearchkit/brk?tab=readme-ov-file#hosting-as-a-service", + url: () => "/hosting", + title: "Link to hosting service", }, ], }, @@ -4094,43 +4107,32 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) { tree: [ { name: "GitHub", - url: () => "https://github.com/bitcoinresearchkit/brk", + url: () => "/github", + title: "Link to Github", }, { name: "Nostr", - url: () => - "https://primal.net/p/npub1jagmm3x39lmwfnrtvxcs9ac7g300y3dusv9lgzhk2e4x5frpxlrqa73v44", + url: () => "/nostr", + title: "Link to BRK's nostr account", }, { name: "Discord", - url: () => "https://discord.com/invite/HaR3wpH3nr", + url: () => "/discord", + title: "Link to BRK's discord server", }, ], }, { name: "Donate", - tree: [ - { - name: "Bitcoin", - qrcode: true, - url: () => "bitcoin:bc1q098zsm89m7kgyze338vfejhpdt92ua9p3peuve", - }, - { - name: "Lightning", - qrcode: true, - url: () => - "lightning:lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhkxmmww3jkuar8d35kgetj8yuq363hv4", - }, - { - name: "Geyser", - url: () => "https://geyser.fund/project/brk", - }, - ], + qrcode: true, + url: () => "bitcoin:bc1q098zsm89m7kgyze338vfejhpdt92ua9p3peuve", + title: "Bitcoin address for donations", }, { name: "Share", qrcode: true, url: () => window.location.href, + title: "Share", }, ]; } @@ -4246,7 +4248,12 @@ export function initOptions({ * @param {string[] | undefined} parentPath * @returns {Accessor} */ - function recursiveProcessPartialTree(partialTree, parent, parentPath = []) { + function recursiveProcessPartialTree( + partialTree, + parent, + parentPath = [], + depth = 0, + ) { /** @type {Accessor[]} */ const listForSum = []; @@ -4306,6 +4313,7 @@ export function initOptions({ anyPartial.tree, passedDetails, [...parentPath, serName], + depth + 1, ); listForSum.push(childOptionsCount); @@ -4317,7 +4325,7 @@ export function initOptions({ } signals.createEffect(selected, (selected) => { - if (selected.path.includes(serName)) { + if (selected.path[depth] === serName) { li.dataset.highlight = ""; } else { delete li.dataset.highlight; diff --git a/websites/bitview/scripts/simulation.js b/websites/bitview/scripts/simulation.js index 2a1f915da..39dc0a632 100644 --- a/websites/bitview/scripts/simulation.js +++ b/websites/bitview/scripts/simulation.js @@ -836,7 +836,7 @@ export function init({ }); vecsResources - .getOrCreate(/** @satisfies {DateIndex} */ (0), "close") + .getOrCreate(/** @satisfies {DateIndex} */ (0), "price_close") .fetch() .then((_closes) => { if (!_closes) return; diff --git a/websites/bitview/scripts/table.js b/websites/bitview/scripts/table.js index fba8e74e5..ac215c325 100644 --- a/websites/bitview/scripts/table.js +++ b/websites/bitview/scripts/table.js @@ -422,6 +422,8 @@ function createSerializedIndexes() { /** @satisfies {VecId} */ ("unknownoutputindex"), /** @satisfies {VecId} */ ("weekindex"), /** @satisfies {VecId} */ ("yearindex"), + /** @satisfies {VecId} */ ("loadedaddressindex"), + /** @satisfies {VecId} */ ("emptyaddressindex"), ]); } /** @typedef {ReturnType} SerializedIndexes */ @@ -483,6 +485,10 @@ function serializedIndexToIndex(serializedIndex) { return /** @satisfies {EmptyOutputIndex} */ (3); case "unknownoutputindex": return /** @satisfies {UnknownOutputIndex} */ (22); + case "emptyaddressindex": + return /** @satisfies {EmptyAddressIndex} */ (26); + case "loadedaddressindex": + return /** @satisfies {LoadedAddressIndex} */ (25); } } @@ -514,7 +520,7 @@ function createIndexToVecIds(vecIdToIndexes) { */ function serializeValue({ value, unit }) { if (typeof value !== "number") { - return String(value); + return JSON.stringify(value); } else if (value !== 18446744073709552000) { if (unit === "USD" || unit === "Difficulty" || unit === "sat/vB") { return value.toLocaleString("en-us", { diff --git a/websites/bitview/service-worker.js b/websites/bitview/service-worker.js index 7e92bd925..264dc9b75 100644 --- a/websites/bitview/service-worker.js +++ b/websites/bitview/service-worker.js @@ -53,11 +53,17 @@ sw.addEventListener("fetch", (event) => { if ( req.method !== "GET" || url.pathname.startsWith("/api") || - url.pathname === "/discord" || - url.pathname === "/github" || url.pathname === "/mcp" || + url.pathname === "/crates" || + url.pathname === "/github" || + url.pathname === "/status" || + url.pathname === "/cli" || + url.pathname === "/hosting" || url.pathname === "/nostr" || - url.pathname === "/status" + url.pathname === "/discord" || + url.pathname === "/nostr" || + url.pathname === "/health" || + url.pathname === "/version" ) { return; // let the browser handle it }