mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
crates: snapshot
This commit is contained in:
@@ -17,7 +17,7 @@ full = [
|
||||
"computer",
|
||||
"error",
|
||||
"fetcher",
|
||||
"grouper",
|
||||
"cohort",
|
||||
"indexer",
|
||||
"iterator",
|
||||
"logger",
|
||||
@@ -38,7 +38,7 @@ client = ["brk_client"]
|
||||
computer = ["brk_computer"]
|
||||
error = ["brk_error"]
|
||||
fetcher = ["brk_fetcher"]
|
||||
grouper = ["brk_grouper"]
|
||||
cohort = ["brk_cohort"]
|
||||
indexer = ["brk_indexer"]
|
||||
iterator = ["brk_iterator"]
|
||||
logger = ["brk_logger"]
|
||||
@@ -60,7 +60,7 @@ brk_client = { workspace = true, optional = true }
|
||||
brk_computer = { workspace = true, optional = true }
|
||||
brk_error = { workspace = true, optional = true }
|
||||
brk_fetcher = { workspace = true, optional = true }
|
||||
brk_grouper = { workspace = true, optional = true }
|
||||
brk_cohort = { workspace = true, optional = true }
|
||||
brk_indexer = { workspace = true, optional = true }
|
||||
brk_iterator = { workspace = true, optional = true }
|
||||
brk_logger = { workspace = true, optional = true }
|
||||
|
||||
@@ -29,7 +29,7 @@ use brk::types::Height;
|
||||
| `computer` | `brk_computer` | Metric computation |
|
||||
| `error` | `brk_error` | Error types |
|
||||
| `fetcher` | `brk_fetcher` | Price data fetching |
|
||||
| `grouper` | `brk_grouper` | Cohort filtering |
|
||||
| `cohort` | `brk_cohort` | Cohort filtering |
|
||||
| `indexer` | `brk_indexer` | Blockchain indexing |
|
||||
| `iterator` | `brk_iterator` | Block iteration |
|
||||
| `logger` | `brk_logger` | Logging setup |
|
||||
|
||||
@@ -16,6 +16,10 @@ pub use brk_bundler as bundler;
|
||||
#[doc(inline)]
|
||||
pub use brk_client as client;
|
||||
|
||||
#[cfg(feature = "cohort")]
|
||||
#[doc(inline)]
|
||||
pub use brk_cohort as cohort;
|
||||
|
||||
#[cfg(feature = "computer")]
|
||||
#[doc(inline)]
|
||||
pub use brk_computer as computer;
|
||||
@@ -28,10 +32,6 @@ pub use brk_error as error;
|
||||
#[doc(inline)]
|
||||
pub use brk_fetcher as fetcher;
|
||||
|
||||
#[cfg(feature = "grouper")]
|
||||
#[doc(inline)]
|
||||
pub use brk_grouper as grouper;
|
||||
|
||||
#[cfg(feature = "indexer")]
|
||||
#[doc(inline)]
|
||||
pub use brk_indexer as indexer;
|
||||
|
||||
@@ -9,7 +9,7 @@ repository.workspace = true
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
brk_grouper = { workspace = true }
|
||||
brk_cohort = { workspace = true }
|
||||
brk_query = { workspace = true }
|
||||
brk_types = { workspace = true }
|
||||
oas3 = "0.20"
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{collections::HashSet, fmt::Write as FmtWrite, fs, io, path::Path};
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use brk_grouper::{
|
||||
use brk_cohort::{
|
||||
AGE_RANGE_NAMES, AMOUNT_RANGE_NAMES, EPOCH_NAMES, GE_AMOUNT_NAMES, LT_AMOUNT_NAMES,
|
||||
MAX_AGE_NAMES, MIN_AGE_NAMES, SPENDABLE_TYPE_NAMES, TERM_NAMES, YEAR_NAMES,
|
||||
};
|
||||
@@ -373,6 +373,14 @@ class MetricNode {{
|
||||
this._path = path;
|
||||
}}
|
||||
|
||||
/**
|
||||
* Get the path for this metric.
|
||||
* @returns {{string}}
|
||||
*/
|
||||
get path() {{
|
||||
return this._path;
|
||||
}}
|
||||
|
||||
/**
|
||||
* Fetch all data points for this metric.
|
||||
* @param {{(value: T[]) => void}} [onUpdate] - Called when data is available (may be called twice: cache then fresh)
|
||||
@@ -473,11 +481,12 @@ fn generate_index_accessors(output: &mut String, patterns: &[IndexSetPattern]) {
|
||||
}
|
||||
writeln!(output, " */\n").unwrap();
|
||||
|
||||
// Outer type with 'by' property
|
||||
// Outer type with 'by' property and indexes method
|
||||
writeln!(output, "/**").unwrap();
|
||||
writeln!(output, " * @template T").unwrap();
|
||||
writeln!(output, " * @typedef {{Object}} {}", pattern.name).unwrap();
|
||||
writeln!(output, " * @property {{{}<T>}} by", by_type_name).unwrap();
|
||||
writeln!(output, " * @property {{() => Index[]}} indexes").unwrap();
|
||||
writeln!(output, " */\n").unwrap();
|
||||
|
||||
// Generate factory function
|
||||
@@ -512,6 +521,9 @@ fn generate_index_accessors(output: &mut String, patterns: &[IndexSetPattern]) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
writeln!(output, " }},").unwrap();
|
||||
writeln!(output, " indexes() {{").unwrap();
|
||||
writeln!(output, " return /** @type {{Index[]}} */ (Object.keys(this.by));").unwrap();
|
||||
writeln!(output, " }}").unwrap();
|
||||
writeln!(output, " }};").unwrap();
|
||||
writeln!(output, "}}\n").unwrap();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{collections::HashSet, fmt::Write as FmtWrite, fs, io, path::Path};
|
||||
|
||||
use brk_grouper::{
|
||||
use brk_cohort::{
|
||||
AGE_RANGE_NAMES, AMOUNT_RANGE_NAMES, EPOCH_NAMES, GE_AMOUNT_NAMES, LT_AMOUNT_NAMES,
|
||||
MAX_AGE_NAMES, MIN_AGE_NAMES, SPENDABLE_TYPE_NAMES, TERM_NAMES, YEAR_NAMES,
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ fn generate_imports(output: &mut String) {
|
||||
output,
|
||||
r#"use std::sync::Arc;
|
||||
use serde::de::DeserializeOwned;
|
||||
pub use brk_grouper::*;
|
||||
pub use brk_cohort::*;
|
||||
pub use brk_types::*;
|
||||
|
||||
"#
|
||||
|
||||
@@ -9,7 +9,7 @@ repository.workspace = true
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
brk_grouper = { workspace = true }
|
||||
brk_cohort = { workspace = true }
|
||||
brk_types = { workspace = true }
|
||||
minreq = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
use serde::de::DeserializeOwned;
|
||||
pub use brk_grouper::*;
|
||||
pub use brk_cohort::*;
|
||||
pub use brk_types::*;
|
||||
|
||||
|
||||
@@ -1136,31 +1136,31 @@ impl<T: DeserializeOwned> BitcoinPattern<T> {
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BlockSizePattern<T> {
|
||||
pub average: Indexes3<T>,
|
||||
pub average: Indexes4<T>,
|
||||
pub cumulative: Indexes3<T>,
|
||||
pub max: Indexes3<T>,
|
||||
pub median: Indexes2<T>,
|
||||
pub min: Indexes3<T>,
|
||||
pub pct10: Indexes2<T>,
|
||||
pub pct25: Indexes2<T>,
|
||||
pub pct75: Indexes2<T>,
|
||||
pub pct90: Indexes2<T>,
|
||||
pub sum: Indexes3<T>,
|
||||
pub max: Indexes4<T>,
|
||||
pub median: Indexes5<T>,
|
||||
pub min: Indexes4<T>,
|
||||
pub pct10: Indexes5<T>,
|
||||
pub pct25: Indexes5<T>,
|
||||
pub pct75: Indexes5<T>,
|
||||
pub pct90: Indexes5<T>,
|
||||
pub sum: Indexes4<T>,
|
||||
}
|
||||
|
||||
impl<T: DeserializeOwned> BlockSizePattern<T> {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
average: Indexes3::new(client.clone(), &format!("{base_path}_average")),
|
||||
average: Indexes4::new(client.clone(), &format!("{base_path}_average")),
|
||||
cumulative: Indexes3::new(client.clone(), &format!("{base_path}_cumulative")),
|
||||
max: Indexes3::new(client.clone(), &format!("{base_path}_max")),
|
||||
median: Indexes2::new(client.clone(), &format!("{base_path}_median")),
|
||||
min: Indexes3::new(client.clone(), &format!("{base_path}_min")),
|
||||
pct10: Indexes2::new(client.clone(), &format!("{base_path}_pct10")),
|
||||
pct25: Indexes2::new(client.clone(), &format!("{base_path}_pct25")),
|
||||
pct75: Indexes2::new(client.clone(), &format!("{base_path}_pct75")),
|
||||
pct90: Indexes2::new(client.clone(), &format!("{base_path}_pct90")),
|
||||
sum: Indexes3::new(client.clone(), &format!("{base_path}_sum")),
|
||||
max: Indexes4::new(client.clone(), &format!("{base_path}_max")),
|
||||
median: Indexes5::new(client.clone(), &format!("{base_path}_median")),
|
||||
min: Indexes4::new(client.clone(), &format!("{base_path}_min")),
|
||||
pct10: Indexes5::new(client.clone(), &format!("{base_path}_pct10")),
|
||||
pct25: Indexes5::new(client.clone(), &format!("{base_path}_pct25")),
|
||||
pct75: Indexes5::new(client.clone(), &format!("{base_path}_pct75")),
|
||||
pct90: Indexes5::new(client.clone(), &format!("{base_path}_pct90")),
|
||||
sum: Indexes4::new(client.clone(), &format!("{base_path}_sum")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1223,29 +1223,57 @@ impl RelativePattern {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BlockIntervalPattern<T> {
|
||||
pub average: Indexes3<T>,
|
||||
pub max: Indexes3<T>,
|
||||
pub median: Indexes2<T>,
|
||||
pub min: Indexes3<T>,
|
||||
pub pct10: Indexes2<T>,
|
||||
pub pct25: Indexes2<T>,
|
||||
pub pct75: Indexes2<T>,
|
||||
pub pct90: Indexes2<T>,
|
||||
}
|
||||
|
||||
impl<T: DeserializeOwned> BlockIntervalPattern<T> {
|
||||
/// Create a new pattern node with accumulated metric name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: &str) -> Self {
|
||||
Self {
|
||||
average: Indexes3::new(client.clone(), &format!("{acc}_avg")),
|
||||
max: Indexes3::new(client.clone(), &format!("{acc}_max")),
|
||||
median: Indexes2::new(client.clone(), &format!("{acc}_median")),
|
||||
min: Indexes3::new(client.clone(), &format!("{acc}_min")),
|
||||
pct10: Indexes2::new(client.clone(), &format!("{acc}_pct10")),
|
||||
pct25: Indexes2::new(client.clone(), &format!("{acc}_pct25")),
|
||||
pct75: Indexes2::new(client.clone(), &format!("{acc}_pct75")),
|
||||
pct90: Indexes2::new(client.clone(), &format!("{acc}_pct90")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct AddresstypeToHeightToAddrCountPattern<T> {
|
||||
pub p2a: Indexes14<T>,
|
||||
pub p2pk33: Indexes15<T>,
|
||||
pub p2pk65: Indexes16<T>,
|
||||
pub p2pkh: Indexes17<T>,
|
||||
pub p2sh: Indexes18<T>,
|
||||
pub p2tr: Indexes19<T>,
|
||||
pub p2wpkh: Indexes20<T>,
|
||||
pub p2wsh: Indexes21<T>,
|
||||
pub p2a: Indexes2<T>,
|
||||
pub p2pk33: Indexes2<T>,
|
||||
pub p2pk65: Indexes2<T>,
|
||||
pub p2pkh: Indexes2<T>,
|
||||
pub p2sh: Indexes2<T>,
|
||||
pub p2tr: Indexes2<T>,
|
||||
pub p2wpkh: Indexes2<T>,
|
||||
pub p2wsh: Indexes2<T>,
|
||||
}
|
||||
|
||||
impl<T: DeserializeOwned> AddresstypeToHeightToAddrCountPattern<T> {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
p2a: Indexes14::new(client.clone(), &format!("{base_path}_p2a")),
|
||||
p2pk33: Indexes15::new(client.clone(), &format!("{base_path}_p2pk33")),
|
||||
p2pk65: Indexes16::new(client.clone(), &format!("{base_path}_p2pk65")),
|
||||
p2pkh: Indexes17::new(client.clone(), &format!("{base_path}_p2pkh")),
|
||||
p2sh: Indexes18::new(client.clone(), &format!("{base_path}_p2sh")),
|
||||
p2tr: Indexes19::new(client.clone(), &format!("{base_path}_p2tr")),
|
||||
p2wpkh: Indexes20::new(client.clone(), &format!("{base_path}_p2wpkh")),
|
||||
p2wsh: Indexes21::new(client.clone(), &format!("{base_path}_p2wsh")),
|
||||
p2a: Indexes2::new(client.clone(), &format!("{base_path}_p2a")),
|
||||
p2pk33: Indexes2::new(client.clone(), &format!("{base_path}_p2pk33")),
|
||||
p2pk65: Indexes2::new(client.clone(), &format!("{base_path}_p2pk65")),
|
||||
p2pkh: Indexes2::new(client.clone(), &format!("{base_path}_p2pkh")),
|
||||
p2sh: Indexes2::new(client.clone(), &format!("{base_path}_p2sh")),
|
||||
p2tr: Indexes2::new(client.clone(), &format!("{base_path}_p2tr")),
|
||||
p2wpkh: Indexes2::new(client.clone(), &format!("{base_path}_p2wpkh")),
|
||||
p2wsh: Indexes2::new(client.clone(), &format!("{base_path}_p2wsh")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1278,34 +1306,6 @@ impl<T: DeserializeOwned> Constant0Pattern<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BlockIntervalPattern<T> {
|
||||
pub average: Indexes3<T>,
|
||||
pub max: Indexes3<T>,
|
||||
pub median: Indexes2<T>,
|
||||
pub min: Indexes3<T>,
|
||||
pub pct10: Indexes2<T>,
|
||||
pub pct25: Indexes2<T>,
|
||||
pub pct75: Indexes2<T>,
|
||||
pub pct90: Indexes2<T>,
|
||||
}
|
||||
|
||||
impl<T: DeserializeOwned> BlockIntervalPattern<T> {
|
||||
/// Create a new pattern node with accumulated metric name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: &str) -> Self {
|
||||
Self {
|
||||
average: Indexes3::new(client.clone(), &format!("{acc}_avg")),
|
||||
max: Indexes3::new(client.clone(), &format!("{acc}_max")),
|
||||
median: Indexes2::new(client.clone(), &format!("{acc}_median")),
|
||||
min: Indexes3::new(client.clone(), &format!("{acc}_min")),
|
||||
pct10: Indexes2::new(client.clone(), &format!("{acc}_pct10")),
|
||||
pct25: Indexes2::new(client.clone(), &format!("{acc}_pct25")),
|
||||
pct75: Indexes2::new(client.clone(), &format!("{acc}_pct75")),
|
||||
pct90: Indexes2::new(client.clone(), &format!("{acc}_pct90")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct _0satsPattern {
|
||||
pub activity: ActivityPattern,
|
||||
@@ -1332,21 +1332,21 @@ impl _0satsPattern {
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct UpTo1dPattern {
|
||||
pub struct _10yTo12yPattern {
|
||||
pub activity: ActivityPattern,
|
||||
pub price_paid: PricePaidPattern2,
|
||||
pub realized: RealizedPattern3,
|
||||
pub realized: RealizedPattern2,
|
||||
pub relative: RelativePattern2,
|
||||
pub supply: SupplyPattern2,
|
||||
pub unrealized: UnrealizedPattern,
|
||||
}
|
||||
|
||||
impl UpTo1dPattern {
|
||||
impl _10yTo12yPattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
activity: ActivityPattern::new(client.clone(), &format!("{base_path}_activity")),
|
||||
price_paid: PricePaidPattern2::new(client.clone(), &format!("{base_path}_price_paid")),
|
||||
realized: RealizedPattern3::new(client.clone(), &format!("{base_path}_realized")),
|
||||
realized: RealizedPattern2::new(client.clone(), &format!("{base_path}_realized")),
|
||||
relative: RelativePattern2::new(client.clone(), &format!("{base_path}_relative")),
|
||||
supply: SupplyPattern2::new(client.clone(), &format!("{base_path}_supply")),
|
||||
unrealized: UnrealizedPattern::new(client.clone(), &format!("{base_path}_unrealized")),
|
||||
@@ -1378,21 +1378,21 @@ impl _0satsPattern2 {
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct _10yTo12yPattern {
|
||||
pub struct UpTo1dPattern {
|
||||
pub activity: ActivityPattern,
|
||||
pub price_paid: PricePaidPattern2,
|
||||
pub realized: RealizedPattern2,
|
||||
pub realized: RealizedPattern3,
|
||||
pub relative: RelativePattern2,
|
||||
pub supply: SupplyPattern2,
|
||||
pub unrealized: UnrealizedPattern,
|
||||
}
|
||||
|
||||
impl _10yTo12yPattern {
|
||||
impl UpTo1dPattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
activity: ActivityPattern::new(client.clone(), &format!("{base_path}_activity")),
|
||||
price_paid: PricePaidPattern2::new(client.clone(), &format!("{base_path}_price_paid")),
|
||||
realized: RealizedPattern2::new(client.clone(), &format!("{base_path}_realized")),
|
||||
realized: RealizedPattern3::new(client.clone(), &format!("{base_path}_realized")),
|
||||
relative: RelativePattern2::new(client.clone(), &format!("{base_path}_relative")),
|
||||
supply: SupplyPattern2::new(client.clone(), &format!("{base_path}_supply")),
|
||||
unrealized: UnrealizedPattern::new(client.clone(), &format!("{base_path}_unrealized")),
|
||||
@@ -1442,25 +1442,6 @@ impl SupplyPattern2 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct SupplyPattern {
|
||||
pub base: Indexes2<Sats>,
|
||||
pub bitcoin: Indexes<Bitcoin>,
|
||||
pub dollars: Indexes<Dollars>,
|
||||
pub sats: Indexes<Sats>,
|
||||
}
|
||||
|
||||
impl SupplyPattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
base: Indexes2::new(client.clone(), &format!("{base_path}_base")),
|
||||
bitcoin: Indexes::new(client.clone(), &format!("{base_path}_bitcoin")),
|
||||
dollars: Indexes::new(client.clone(), &format!("{base_path}_dollars")),
|
||||
sats: Indexes::new(client.clone(), &format!("{base_path}_sats")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct FeePattern2 {
|
||||
pub base: Indexes2<Sats>,
|
||||
@@ -1481,18 +1462,20 @@ impl FeePattern2 {
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct PricePaidPattern2 {
|
||||
pub max_price_paid: Indexes3<Dollars>,
|
||||
pub min_price_paid: Indexes3<Dollars>,
|
||||
pub price_percentiles: PricePercentilesPattern,
|
||||
pub struct SupplyPattern {
|
||||
pub base: Indexes2<Sats>,
|
||||
pub bitcoin: Indexes<Bitcoin>,
|
||||
pub dollars: Indexes<Dollars>,
|
||||
pub sats: Indexes<Sats>,
|
||||
}
|
||||
|
||||
impl PricePaidPattern2 {
|
||||
impl SupplyPattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
max_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_max_price_paid")),
|
||||
min_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_min_price_paid")),
|
||||
price_percentiles: PricePercentilesPattern::new(client.clone(), &format!("{base_path}_price_percentiles")),
|
||||
base: Indexes2::new(client.clone(), &format!("{base_path}_base")),
|
||||
bitcoin: Indexes::new(client.clone(), &format!("{base_path}_bitcoin")),
|
||||
dollars: Indexes::new(client.clone(), &format!("{base_path}_dollars")),
|
||||
sats: Indexes::new(client.clone(), &format!("{base_path}_sats")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1515,18 +1498,18 @@ impl CoinbasePattern {
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct UnclaimedRewardsPattern {
|
||||
pub bitcoin: BlockCountPattern<Bitcoin>,
|
||||
pub dollars: BlockCountPattern<Dollars>,
|
||||
pub sats: BlockCountPattern<Sats>,
|
||||
pub struct PricePaidPattern2 {
|
||||
pub max_price_paid: Indexes3<Dollars>,
|
||||
pub min_price_paid: Indexes3<Dollars>,
|
||||
pub price_percentiles: PricePercentilesPattern,
|
||||
}
|
||||
|
||||
impl UnclaimedRewardsPattern {
|
||||
impl PricePaidPattern2 {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
bitcoin: BlockCountPattern::new(client.clone(), &format!("{base_path}_bitcoin")),
|
||||
dollars: BlockCountPattern::new(client.clone(), &format!("{base_path}_dollars")),
|
||||
sats: BlockCountPattern::new(client.clone(), &format!("{base_path}_sats")),
|
||||
max_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_max_price_paid")),
|
||||
min_price_paid: Indexes3::new(client.clone(), &format!("{base_path}_min_price_paid")),
|
||||
price_percentiles: PricePercentilesPattern::new(client.clone(), &format!("{base_path}_price_percentiles")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1548,6 +1531,23 @@ impl ActiveSupplyPattern {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct UnclaimedRewardsPattern {
|
||||
pub bitcoin: BlockCountPattern<Bitcoin>,
|
||||
pub dollars: BlockCountPattern<Dollars>,
|
||||
pub sats: BlockCountPattern<Sats>,
|
||||
}
|
||||
|
||||
impl UnclaimedRewardsPattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
bitcoin: BlockCountPattern::new(client.clone(), &format!("{base_path}_bitcoin")),
|
||||
dollars: BlockCountPattern::new(client.clone(), &format!("{base_path}_dollars")),
|
||||
sats: BlockCountPattern::new(client.clone(), &format!("{base_path}_sats")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BlockCountPattern<T> {
|
||||
pub base: Indexes2<T>,
|
||||
@@ -1565,6 +1565,22 @@ impl<T: DeserializeOwned> BlockCountPattern<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct _1dReturns1mSdPattern {
|
||||
pub sd: Indexes<StoredF32>,
|
||||
pub sma: Indexes<StoredF32>,
|
||||
}
|
||||
|
||||
impl _1dReturns1mSdPattern {
|
||||
/// Create a new pattern node with accumulated metric name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: &str) -> Self {
|
||||
Self {
|
||||
sd: Indexes::new(client.clone(), &format!("{acc}_sd")),
|
||||
sma: Indexes::new(client.clone(), &format!("{acc}_sma")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct SatsPattern {
|
||||
pub cumulative: Indexes3<Sats>,
|
||||
@@ -1580,21 +1596,6 @@ impl SatsPattern {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct SupplyValuePattern {
|
||||
pub bitcoin: Indexes2<Bitcoin>,
|
||||
pub dollars: Indexes2<Dollars>,
|
||||
}
|
||||
|
||||
impl SupplyValuePattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
bitcoin: Indexes2::new(client.clone(), &format!("{base_path}_bitcoin")),
|
||||
dollars: Indexes2::new(client.clone(), &format!("{base_path}_dollars")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct PricePaidPattern {
|
||||
pub max_price_paid: Indexes3<Dollars>,
|
||||
@@ -1611,17 +1612,16 @@ impl PricePaidPattern {
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct _1dReturns1mSdPattern {
|
||||
pub sd: Indexes<StoredF32>,
|
||||
pub sma: Indexes<StoredF32>,
|
||||
pub struct SupplyValuePattern {
|
||||
pub bitcoin: Indexes2<Bitcoin>,
|
||||
pub dollars: Indexes2<Dollars>,
|
||||
}
|
||||
|
||||
impl _1dReturns1mSdPattern {
|
||||
/// Create a new pattern node with accumulated metric name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: &str) -> Self {
|
||||
impl SupplyValuePattern {
|
||||
pub fn new(client: Arc<BrkClientBase>, base_path: &str) -> Self {
|
||||
Self {
|
||||
sd: Indexes::new(client.clone(), &format!("{acc}_sd")),
|
||||
sma: Indexes::new(client.clone(), &format!("{acc}_sma")),
|
||||
bitcoin: Indexes2::new(client.clone(), &format!("{base_path}_bitcoin")),
|
||||
dollars: Indexes2::new(client.clone(), &format!("{base_path}_dollars")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "brk_grouper"
|
||||
description = "Groups used throughout BRK"
|
||||
name = "brk_cohort"
|
||||
description = "Cohort definitions used throughout BRK"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
@@ -1,4 +1,4 @@
|
||||
# brk_grouper
|
||||
# brk_cohort
|
||||
|
||||
UTXO and address cohort filtering for on-chain analytics.
|
||||
|
||||
@@ -12,7 +12,7 @@ build = "build.rs"
|
||||
bitcoin = { workspace = true }
|
||||
brk_error = { workspace = true }
|
||||
brk_fetcher = { workspace = true }
|
||||
brk_grouper = { workspace = true }
|
||||
brk_cohort = { workspace = true }
|
||||
brk_indexer = { workspace = true }
|
||||
brk_iterator = { workspace = true }
|
||||
brk_logger = { workspace = true }
|
||||
|
||||
@@ -67,7 +67,7 @@ Use [mimalloc v3](https://crates.io/crates/mimalloc) as the global allocator to
|
||||
## Built On
|
||||
|
||||
- `brk_indexer` for indexed blockchain data
|
||||
- `brk_cohort` for cohort filtering
|
||||
- `brk_fetcher` for price data
|
||||
- `brk_reader` for raw block access
|
||||
- `brk_grouper` for cohort filtering
|
||||
- `brk_traversable` for data export
|
||||
|
||||
@@ -10,7 +10,7 @@ use vecdb::{
|
||||
TypedVecIterator,
|
||||
};
|
||||
|
||||
use super::Indexes;
|
||||
use super::ComputeIndexes;
|
||||
|
||||
pub const DB_NAME: &str = "blks";
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
reader: &Reader,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -62,7 +62,7 @@ impl Vecs {
|
||||
fn compute_(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
parser: &Reader,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -4,14 +4,14 @@ use brk_types::{CheckedSub, Height, StoredU32, StoredU64, Timestamp};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{Indexes, indexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let mut height_to_timestamp_fixed_iter =
|
||||
@@ -134,6 +134,34 @@ impl Vecs {
|
||||
Some(&self.height_to_vbytes),
|
||||
)?;
|
||||
|
||||
// Timestamp metrics (moved from epoch)
|
||||
self.timeindexes_to_timestamp
|
||||
.compute_all(starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.time.dateindex_to_date,
|
||||
|(di, d, ..)| (di, Timestamp::from(d)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let mut height_to_timestamp_iter = indexer.vecs.block.height_to_timestamp.iter()?;
|
||||
|
||||
self.difficultyepoch_to_timestamp.compute_transform(
|
||||
starting_indexes.difficultyepoch,
|
||||
&indexes.block.difficultyepoch_to_first_height,
|
||||
|(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.halvingepoch_to_timestamp.compute_transform(
|
||||
starting_indexes.halvingepoch,
|
||||
&indexes.block.halvingepoch_to_first_height,
|
||||
|(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,15 @@ use vecdb::{Database, EagerVec, ImportableVec, IterableCloneableVec, LazyVecFrom
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
chain::{
|
||||
TARGET_BLOCKS_PER_DAY, TARGET_BLOCKS_PER_DECADE, TARGET_BLOCKS_PER_MONTH,
|
||||
TARGET_BLOCKS_PER_QUARTER, TARGET_BLOCKS_PER_SEMESTER, TARGET_BLOCKS_PER_WEEK,
|
||||
TARGET_BLOCKS_PER_YEAR,
|
||||
},
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
use crate::chain::{
|
||||
TARGET_BLOCKS_PER_DAY, TARGET_BLOCKS_PER_DECADE, TARGET_BLOCKS_PER_MONTH,
|
||||
TARGET_BLOCKS_PER_QUARTER, TARGET_BLOCKS_PER_SEMESTER, TARGET_BLOCKS_PER_WEEK,
|
||||
TARGET_BLOCKS_PER_YEAR,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
@@ -166,6 +165,17 @@ impl Vecs {
|
||||
indexes,
|
||||
full_stats(),
|
||||
)?,
|
||||
// Timestamp metrics (moved from epoch)
|
||||
difficultyepoch_to_timestamp: EagerVec::forced_import(db, "timestamp", version + v0)?,
|
||||
halvingepoch_to_timestamp: EagerVec::forced_import(db, "timestamp", version + v0)?,
|
||||
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"timestamp",
|
||||
Source::Compute,
|
||||
version + v0,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
DateIndex, DecadeIndex, Height, MonthIndex, QuarterIndex, SemesterIndex, StoredU32, StoredU64,
|
||||
Timestamp, WeekIndex, Weight, YearIndex,
|
||||
DateIndex, DecadeIndex, DifficultyEpoch, HalvingEpoch, Height, MonthIndex, QuarterIndex,
|
||||
SemesterIndex, StoredU32, StoredU64, Timestamp, WeekIndex, Weight, YearIndex,
|
||||
};
|
||||
use vecdb::{EagerVec, LazyVecFrom1, PcoVec};
|
||||
|
||||
use crate::grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
|
||||
|
||||
/// Block-related metrics: count, interval, size, weight, vbytes
|
||||
/// Block-related metrics: count, interval, size, weight, vbytes, timestamps
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub dateindex_to_block_count_target: LazyVecFrom1<DateIndex, StoredU64, DateIndex, DateIndex>,
|
||||
@@ -32,4 +32,7 @@ pub struct Vecs {
|
||||
pub indexes_to_block_size: ComputedVecsFromHeight<StoredU64>,
|
||||
pub indexes_to_block_vbytes: ComputedVecsFromHeight<StoredU64>,
|
||||
pub indexes_to_block_weight: ComputedVecsFromHeight<Weight>,
|
||||
pub difficultyepoch_to_timestamp: EagerVec<PcoVec<DifficultyEpoch, Timestamp>>,
|
||||
pub halvingepoch_to_timestamp: EagerVec<PcoVec<HalvingEpoch, Timestamp>>,
|
||||
pub timeindexes_to_timestamp: ComputedVecsFromDateIndex<Timestamp>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, IterableVec, TypedVecIterator, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
chain::{block, transaction},
|
||||
indexes, price,
|
||||
utils::OptionExt,
|
||||
@@ -19,7 +19,7 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
block_vecs: &block::Vecs,
|
||||
transaction_vecs: &transaction::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use crate::{indexes, price, txins, Indexes};
|
||||
use crate::{indexes, price, txins, ComputeIndexes};
|
||||
|
||||
use super::Vecs;
|
||||
|
||||
@@ -12,13 +12,13 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
txins: &txins::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Independent computations first
|
||||
self.block.compute(indexer, indexes, starting_indexes, exit)?;
|
||||
self.epoch.compute(indexer, indexes, starting_indexes, exit)?;
|
||||
self.epoch.compute(indexes, starting_indexes, exit)?;
|
||||
self.transaction.compute(indexer, indexes, txins, starting_indexes, price, exit)?;
|
||||
|
||||
// Coinbase depends on block and transaction
|
||||
|
||||
@@ -1,46 +1,17 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::Timestamp;
|
||||
use brk_types::StoredU32;
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{Indexes, indexes};
|
||||
use crate::{chain::TARGET_BLOCKS_PER_DAY_F32, indexes, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.timeindexes_to_timestamp
|
||||
.compute_all(starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.time.dateindex_to_date,
|
||||
|(di, d, ..)| (di, Timestamp::from(d)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let mut height_to_timestamp_iter = indexer.vecs.block.height_to_timestamp.iter()?;
|
||||
|
||||
self.difficultyepoch_to_timestamp.compute_transform(
|
||||
starting_indexes.difficultyepoch,
|
||||
&indexes.block.difficultyepoch_to_first_height,
|
||||
|(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.halvingepoch_to_timestamp.compute_transform(
|
||||
starting_indexes.halvingepoch,
|
||||
&indexes.block.halvingepoch_to_first_height,
|
||||
|(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut height_to_difficultyepoch_iter =
|
||||
indexes.block.height_to_difficultyepoch.into_iter();
|
||||
self.indexes_to_difficultyepoch
|
||||
@@ -80,6 +51,65 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Countdown metrics (moved from mining)
|
||||
self.indexes_to_blocks_before_next_difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.block.height_to_height,
|
||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_days_before_next_difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_blocks_before_next_difficulty_adjustment
|
||||
.height
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_blocks_before_next_halving.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.block.height_to_height,
|
||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_halving())),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_days_before_next_halving.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_blocks_before_next_halving
|
||||
.height
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,20 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
grouped::{ComputedVecsFromDateIndex, Source, VecBuilderOptions},
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
let v2 = Version::TWO;
|
||||
let last = || VecBuilderOptions::default().add_last();
|
||||
|
||||
Ok(Self {
|
||||
difficultyepoch_to_timestamp: EagerVec::forced_import(db, "timestamp", version + v0)?,
|
||||
halvingepoch_to_timestamp: EagerVec::forced_import(db, "timestamp", version + v0)?,
|
||||
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"timestamp",
|
||||
Source::Compute,
|
||||
version + v0,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
"difficultyepoch",
|
||||
@@ -40,6 +31,41 @@ impl Vecs {
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
// Countdown metrics (moved from mining)
|
||||
indexes_to_blocks_before_next_difficulty_adjustment:
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"blocks_before_next_difficulty_adjustment",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_days_before_next_difficulty_adjustment:
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"days_before_next_difficulty_adjustment",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_blocks_before_next_halving: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"blocks_before_next_halving",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_days_before_next_halving: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"days_before_next_halving",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{DifficultyEpoch, HalvingEpoch, Timestamp};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
use brk_types::{DifficultyEpoch, HalvingEpoch, StoredF32, StoredU32};
|
||||
|
||||
use crate::grouped::ComputedVecsFromDateIndex;
|
||||
use crate::grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
|
||||
|
||||
/// Epoch and timestamp metrics
|
||||
/// Epoch metrics: difficulty epochs, halving epochs, and countdown to next epoch
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub difficultyepoch_to_timestamp: EagerVec<PcoVec<DifficultyEpoch, Timestamp>>,
|
||||
pub halvingepoch_to_timestamp: EagerVec<PcoVec<HalvingEpoch, Timestamp>>,
|
||||
pub timeindexes_to_timestamp: ComputedVecsFromDateIndex<Timestamp>,
|
||||
pub indexes_to_difficultyepoch: ComputedVecsFromDateIndex<DifficultyEpoch>,
|
||||
pub indexes_to_halvingepoch: ComputedVecsFromDateIndex<HalvingEpoch>,
|
||||
// Countdown metrics (moved from mining)
|
||||
pub indexes_to_blocks_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_days_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
|
||||
pub indexes_to_blocks_before_next_halving: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_days_before_next_halving: ComputedVecsFromHeight<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{StoredF32, StoredF64, StoredU32};
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
chain::{block, coinbase, ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F32, TARGET_BLOCKS_PER_DAY_F64},
|
||||
chain::{block, coinbase, ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64},
|
||||
indexes,
|
||||
utils::OptionExt,
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -18,7 +18,7 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
block_vecs: &block::Vecs,
|
||||
coinbase_vecs: &coinbase::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_difficulty.compute_rest(
|
||||
@@ -119,64 +119,6 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_blocks_before_next_difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.block.height_to_height,
|
||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_days_before_next_difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_blocks_before_next_difficulty_adjustment
|
||||
.height
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_blocks_before_next_halving.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.block.height_to_height,
|
||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_halving())),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_days_before_next_halving.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.indexes_to_blocks_before_next_halving
|
||||
.height
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_hash_price_ths
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
|
||||
@@ -17,7 +17,6 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
let v2 = Version::TWO;
|
||||
let v4 = Version::new(4);
|
||||
let v5 = Version::new(5);
|
||||
|
||||
@@ -169,40 +168,6 @@ impl Vecs {
|
||||
indexes,
|
||||
sum(),
|
||||
)?,
|
||||
indexes_to_blocks_before_next_difficulty_adjustment:
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"blocks_before_next_difficulty_adjustment",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_days_before_next_difficulty_adjustment:
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"days_before_next_difficulty_adjustment",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_blocks_before_next_halving: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"blocks_before_next_halving",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
indexes_to_days_before_next_halving: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"days_before_next_halving",
|
||||
Source::Compute,
|
||||
version + v2,
|
||||
indexes,
|
||||
last(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredF32, StoredF64, StoredU32};
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
|
||||
use crate::grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
|
||||
|
||||
@@ -24,8 +24,4 @@ pub struct Vecs {
|
||||
pub indexes_to_difficulty: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_difficulty_as_hash: ComputedVecsFromHeight<StoredF32>,
|
||||
pub indexes_to_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
|
||||
pub indexes_to_blocks_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_days_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
|
||||
pub indexes_to_blocks_before_next_halving: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_days_before_next_halving: ComputedVecsFromHeight<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Height, StoredU64};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{chain::transaction, indexes, Indexes};
|
||||
use crate::{chain::transaction, indexes, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -12,7 +12,7 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
transaction_vecs: &transaction::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_p2a_count
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{FeeRate, Sats, StoredU64, TxVersion};
|
||||
use vecdb::{Exit, TypedVecIterator, unlikely};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{Indexes, grouped::ComputedVecsFromHeight, indexes, price, txins};
|
||||
use crate::{ComputeIndexes, grouped::ComputedVecsFromHeight, indexes, price, txins};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -12,7 +12,7 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
txins: &txins::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::Exit;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
chain::{coinbase, transaction},
|
||||
indexes, price, Indexes,
|
||||
indexes, price, ComputeIndexes,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -17,7 +17,7 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
transaction_vecs: &transaction::Vecs,
|
||||
coinbase_vecs: &coinbase::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -8,7 +8,7 @@ use vecdb::{Database, Exit, PAGE_SIZE, TypedVecIterator};
|
||||
use crate::{grouped::ComputedVecsFromDateIndex, utils::OptionExt};
|
||||
|
||||
use super::{
|
||||
Indexes, chain,
|
||||
ComputeIndexes, chain,
|
||||
grouped::{
|
||||
ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, ComputedVecsFromHeight,
|
||||
Source, VecBuilderOptions,
|
||||
@@ -198,7 +198,7 @@ impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
chain: &chain::Vecs,
|
||||
stateful: &stateful::Vecs,
|
||||
@@ -214,7 +214,7 @@ impl Vecs {
|
||||
fn compute_(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
chain: &chain::Vecs,
|
||||
stateful: &stateful::Vecs,
|
||||
|
||||
@@ -10,7 +10,7 @@ use vecdb::{
|
||||
PAGE_SIZE, TypedVecIterator, VecIndex,
|
||||
};
|
||||
|
||||
use super::{Indexes, indexes, utils::OptionExt};
|
||||
use super::{ComputeIndexes, indexes, utils::OptionExt};
|
||||
|
||||
pub const DB_NAME: &str = "fetched";
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.compute_(indexer, indexes, starting_indexes, exit)?;
|
||||
@@ -72,7 +72,7 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let height_to_timestamp = &indexer.vecs.block.height_to_timestamp;
|
||||
|
||||
@@ -9,7 +9,7 @@ use vecdb::{
|
||||
PcoVec,
|
||||
};
|
||||
|
||||
use crate::{Indexes, grouped::LazyVecsBuilder, indexes, utils::OptionExt};
|
||||
use crate::{ComputeIndexes, grouped::LazyVecsBuilder, indexes, utils::OptionExt};
|
||||
|
||||
use crate::grouped::{ComputedVecValue, EagerVecsBuilder, Source, VecBuilderOptions};
|
||||
|
||||
@@ -114,7 +114,7 @@ where
|
||||
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
@@ -129,7 +129,7 @@ where
|
||||
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
dateindex: Option<&impl IterableVec<DateIndex, T>>,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -12,7 +12,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{LazyVecsBuilder, Source},
|
||||
indexes,
|
||||
utils::OptionExt,
|
||||
@@ -139,7 +139,7 @@ where
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
@@ -155,7 +155,7 @@ where
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
height_vec: Option<&impl IterableVec<Height, T>>,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{
|
||||
AnyExportableVec, Database, EagerVec, Exit, ImportableVec, IterableCloneableVec, PcoVec,
|
||||
};
|
||||
|
||||
use crate::{Indexes, indexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use crate::grouped::{ComputedVecValue, EagerVecsBuilder, LazyVecsBuilder, VecBuilderOptions};
|
||||
|
||||
@@ -64,7 +64,7 @@ where
|
||||
|
||||
pub fn compute<F>(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
|
||||
@@ -12,7 +12,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{LazyVecsBuilder, Source},
|
||||
indexes, price,
|
||||
utils::OptionExt,
|
||||
@@ -135,7 +135,7 @@ where
|
||||
// &mut self,
|
||||
// indexer: &Indexer,
|
||||
// indexes: &indexes::Vecs,
|
||||
// starting_indexes: &Indexes,
|
||||
// starting_indexes: &ComputeIndexes,
|
||||
// exit: &Exit,
|
||||
// mut compute: F,
|
||||
// ) -> Result<()>
|
||||
@@ -166,7 +166,7 @@ where
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
txindex: Option<&impl CollectableVec<TxIndex, T>>,
|
||||
) -> Result<()> {
|
||||
@@ -196,7 +196,7 @@ where
|
||||
fn compute_after_height(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.dateindex.from_aligned(
|
||||
@@ -216,7 +216,7 @@ impl ComputedVecsFromTxindex<Bitcoin> {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
sats: &ComputedVecsFromTxindex<Sats>,
|
||||
txindex: Option<&impl CollectableVec<TxIndex, Bitcoin>>,
|
||||
@@ -314,7 +314,7 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
bitcoin: &ComputedVecsFromTxindex<Bitcoin>,
|
||||
txindex: Option<&impl CollectableVec<TxIndex, Dollars>>,
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{
|
||||
AnyExportableVec, AnyStoredVec, Database, EagerVec, Exit, GenericStoredVec, PcoVec,
|
||||
};
|
||||
|
||||
use crate::{Indexes, indexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use super::super::{ComputedVecsFromDateIndex, Source, VecBuilderOptions};
|
||||
|
||||
@@ -65,7 +65,7 @@ impl PricePercentiles {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn compute_rest(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
|
||||
pub fn compute_rest(&mut self, starting_indexes: &ComputeIndexes, exit: &Exit) -> Result<()> {
|
||||
for vec in self.vecs.iter_mut().flatten() {
|
||||
vec.compute_rest(
|
||||
starting_indexes,
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{
|
||||
ComputedStandardDeviationVecsFromDateIndex, LazyVecsFrom2FromDateIndex, PriceTimesRatio,
|
||||
StandardDeviationVecsOptions, source::Source,
|
||||
@@ -157,7 +157,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
compute: F,
|
||||
) -> Result<()>
|
||||
@@ -176,7 +176,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
price_opt: Option<&impl IterableVec<DateIndex, Dollars>>,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -8,7 +8,7 @@ use vecdb::{
|
||||
PcoVec, VecIndex,
|
||||
};
|
||||
|
||||
use crate::{Indexes, grouped::source::Source, indexes, price, utils::OptionExt};
|
||||
use crate::{ComputeIndexes, grouped::source::Source, indexes, price, utils::OptionExt};
|
||||
|
||||
use super::super::{
|
||||
ClosePriceTimesRatio, ComputedVecsFromDateIndex, LazyVecsFrom2FromDateIndex, VecBuilderOptions,
|
||||
@@ -195,7 +195,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
|
||||
pub fn compute_all(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
source: &impl CollectableVec<DateIndex, StoredF32>,
|
||||
) -> Result<()> {
|
||||
@@ -221,7 +221,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
sma_opt: Option<&impl IterableVec<DateIndex, StoredF32>>,
|
||||
source: &impl CollectableVec<DateIndex, StoredF32>,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Bitcoin, DateIndex, Dollars, Sats, Version};
|
||||
use vecdb::{CollectableVec, Database, EagerVec, Exit, IterableCloneableVec, PcoVec};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{ComputedVecsFromDateIndex, LazyVecsFromDateIndex, SatsToBitcoin},
|
||||
indexes, price,
|
||||
traits::ComputeFromBitcoin,
|
||||
@@ -71,7 +71,7 @@ impl ComputedValueVecsFromDateIndex {
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
@@ -89,7 +89,7 @@ impl ComputedValueVecsFromDateIndex {
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
dateindex: Option<&impl CollectableVec<DateIndex, Sats>>,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Bitcoin, Dollars, Height, Sats, Version};
|
||||
use vecdb::{CollectableVec, Database, EagerVec, Exit, IterableCloneableVec, PcoVec};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{LazyVecsFromHeight, SatsToBitcoin, Source},
|
||||
indexes, price,
|
||||
traits::ComputeFromBitcoin,
|
||||
@@ -74,7 +74,7 @@ impl ComputedValueVecsFromHeight {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
mut compute: F,
|
||||
) -> Result<()>
|
||||
@@ -93,7 +93,7 @@ impl ComputedValueVecsFromHeight {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
height: Option<&impl CollectableVec<Height, Sats>>,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{
|
||||
VecIndex,
|
||||
};
|
||||
|
||||
use crate::{Indexes, grouped::Source, indexes, price, utils::OptionExt};
|
||||
use crate::{ComputeIndexes, grouped::Source, indexes, price, utils::OptionExt};
|
||||
|
||||
use crate::grouped::{ComputedVecsFromTxindex, VecBuilderOptions};
|
||||
|
||||
@@ -113,7 +113,7 @@ impl ComputedValueVecsFromTxindex {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
txindex: Option<&impl CollectableVec<TxIndex, Sats>>,
|
||||
price: Option<&price::Vecs>,
|
||||
|
||||
@@ -3,16 +3,15 @@ mod block;
|
||||
mod time;
|
||||
mod transaction;
|
||||
|
||||
use std::{ops::Deref, path::Path};
|
||||
use std::path::Path;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
DateIndex, DecadeIndex, DifficultyEpoch, HalvingEpoch, Height, MonthIndex, QuarterIndex,
|
||||
SemesterIndex, Version, WeekIndex, YearIndex,
|
||||
};
|
||||
use vecdb::{Database, Exit, PAGE_SIZE, TypedVecIterator};
|
||||
use brk_types::{Indexes, Version};
|
||||
|
||||
pub use brk_types::ComputeIndexes;
|
||||
use vecdb::{Database, Exit, PAGE_SIZE};
|
||||
|
||||
pub use address::Vecs as AddressVecs;
|
||||
pub use block::Vecs as BlockVecs;
|
||||
@@ -63,9 +62,9 @@ impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
starting_indexes: brk_indexer::Indexes,
|
||||
starting_indexes: Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<Indexes> {
|
||||
) -> Result<ComputeIndexes> {
|
||||
let indexes = self.compute_(indexer, starting_indexes, exit)?;
|
||||
let _lock = exit.lock();
|
||||
self.db.compact()?;
|
||||
@@ -75,9 +74,9 @@ impl Vecs {
|
||||
fn compute_(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
starting_indexes: brk_indexer::Indexes,
|
||||
starting_indexes: Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<Indexes> {
|
||||
) -> Result<ComputeIndexes> {
|
||||
// Transaction indexes
|
||||
self.transaction.compute(indexer, &starting_indexes, exit)?;
|
||||
|
||||
@@ -90,60 +89,17 @@ impl Vecs {
|
||||
.time
|
||||
.compute(indexer, &starting_indexes, starting_dateindex, &self.block, exit)?;
|
||||
|
||||
Ok(Indexes {
|
||||
indexes: starting_indexes,
|
||||
dateindex: time_indexes.dateindex,
|
||||
weekindex: time_indexes.weekindex,
|
||||
monthindex: time_indexes.monthindex,
|
||||
quarterindex: time_indexes.quarterindex,
|
||||
semesterindex: time_indexes.semesterindex,
|
||||
yearindex: time_indexes.yearindex,
|
||||
decadeindex: time_indexes.decadeindex,
|
||||
difficultyepoch: starting_difficultyepoch,
|
||||
halvingepoch: starting_halvingepoch,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Indexes {
|
||||
indexes: brk_indexer::Indexes,
|
||||
pub dateindex: DateIndex,
|
||||
pub weekindex: WeekIndex,
|
||||
pub monthindex: MonthIndex,
|
||||
pub quarterindex: QuarterIndex,
|
||||
pub semesterindex: SemesterIndex,
|
||||
pub yearindex: YearIndex,
|
||||
pub decadeindex: DecadeIndex,
|
||||
pub difficultyepoch: DifficultyEpoch,
|
||||
pub halvingepoch: HalvingEpoch,
|
||||
}
|
||||
|
||||
impl Indexes {
|
||||
pub fn update_from_height(&mut self, height: Height, indexes: &Vecs) {
|
||||
self.indexes.height = height;
|
||||
self.dateindex = DateIndex::try_from(
|
||||
indexes
|
||||
.block
|
||||
.height_to_date_fixed
|
||||
.into_iter()
|
||||
.get_unwrap(height),
|
||||
)
|
||||
.unwrap();
|
||||
self.weekindex = WeekIndex::from(self.dateindex);
|
||||
self.monthindex = MonthIndex::from(self.dateindex);
|
||||
self.quarterindex = QuarterIndex::from(self.monthindex);
|
||||
self.semesterindex = SemesterIndex::from(self.monthindex);
|
||||
self.yearindex = YearIndex::from(self.monthindex);
|
||||
self.decadeindex = DecadeIndex::from(self.dateindex);
|
||||
self.difficultyepoch = DifficultyEpoch::from(self.height);
|
||||
self.halvingepoch = HalvingEpoch::from(self.height);
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Indexes {
|
||||
type Target = brk_indexer::Indexes;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.indexes
|
||||
Ok(ComputeIndexes::new(
|
||||
starting_indexes,
|
||||
time_indexes.dateindex,
|
||||
time_indexes.weekindex,
|
||||
time_indexes.monthindex,
|
||||
time_indexes.quarterindex,
|
||||
time_indexes.semesterindex,
|
||||
time_indexes.yearindex,
|
||||
time_indexes.decadeindex,
|
||||
starting_difficultyepoch,
|
||||
starting_halvingepoch,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ mod txins;
|
||||
mod txouts;
|
||||
mod utils;
|
||||
|
||||
use indexes::Indexes;
|
||||
use indexes::ComputeIndexes;
|
||||
use utils::OptionExt;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
|
||||
@@ -3,13 +3,13 @@ use brk_types::StoredU16;
|
||||
use vecdb::{Exit, GenericStoredVec, TypedVecIterator, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{Indexes, price, traits::ComputeDrawdown, utils::OptionExt};
|
||||
use crate::{ComputeIndexes, price, traits::ComputeDrawdown, utils::OptionExt};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.height_to_price_ath.compute_all_time_high(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_error::Result;
|
||||
use vecdb::Exit;
|
||||
|
||||
use crate::{price, Indexes};
|
||||
use crate::{price, ComputeIndexes};
|
||||
use crate::utils::OptionExt;
|
||||
|
||||
use super::Vecs;
|
||||
@@ -10,7 +10,7 @@ impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// ATH metrics (independent)
|
||||
|
||||
@@ -7,14 +7,14 @@ use crate::{
|
||||
price,
|
||||
traits::{ComputeDCAAveragePriceViaLen, ComputeDCAStackViaLen},
|
||||
utils::OptionExt,
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let close = price.timeindexes_to_price_close.dateindex.u();
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_error::Result;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{price, utils::OptionExt, Indexes};
|
||||
use crate::{price, utils::OptionExt, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let close = price.timeindexes_to_price_close.dateindex.u();
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_error::Result;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{price, utils::OptionExt, Indexes};
|
||||
use crate::{price, utils::OptionExt, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let close = price.timeindexes_to_price_close.dateindex.u();
|
||||
|
||||
@@ -3,13 +3,13 @@ use brk_types::StoredF32;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{price, utils::OptionExt, Indexes};
|
||||
use crate::{price, utils::OptionExt, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
price: &price::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let open = price.timeindexes_to_price_open.dateindex.u();
|
||||
|
||||
@@ -3,12 +3,12 @@ use brk_types::{DateIndex, StoredF32};
|
||||
use vecdb::{CollectableVec, Exit};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::Indexes;
|
||||
use crate::ComputeIndexes;
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute<V>(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
_1d_price_returns_dateindex: &V,
|
||||
) -> Result<()>
|
||||
|
||||
@@ -15,7 +15,7 @@ mod vecs;
|
||||
|
||||
use crate::{
|
||||
chain,
|
||||
indexes::{self, Indexes},
|
||||
indexes::{self, ComputeIndexes},
|
||||
price,
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -92,7 +92,7 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -109,7 +109,7 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.height_to_pool.validate_computed_version_or_reset(
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
LazyVecsFrom2FromHeight, MaskSats, PercentageU32F32, SatsPlus, SatsPlusToBitcoin, Source,
|
||||
VecBuilderOptions,
|
||||
},
|
||||
indexes::{self, Indexes},
|
||||
indexes::{self, ComputeIndexes},
|
||||
price,
|
||||
};
|
||||
|
||||
@@ -211,7 +211,7 @@ impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_pool: &impl IterableVec<Height, PoolSlug>,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
|
||||
@@ -11,7 +11,7 @@ use vecdb::{BytesVec, Database, EagerVec, Exit, ImportableVec, PAGE_SIZE, PcoVec
|
||||
use crate::{fetched, grouped::Source, utils::OptionExt};
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
@@ -189,7 +189,7 @@ impl Vecs {
|
||||
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
fetched: &fetched::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -201,7 +201,7 @@ impl Vecs {
|
||||
|
||||
fn compute_(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
fetched: &fetched::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use brk_cohort::ByAddressType;
|
||||
use brk_error::Result;
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU64, Version};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
@@ -10,7 +10,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
@@ -192,7 +192,7 @@ impl AddressTypeToIndexesToAddressCount {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
addresstype_to_height_to_addresscount: &AddressTypeToHeightToAddressCount,
|
||||
) -> Result<()> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{collections::hash_map::Entry, mem};
|
||||
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_cohort::ByAddressType;
|
||||
use brk_types::{OutputType, TypeIndex};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use rustc_hash::FxHashMap;
|
||||
@@ -124,4 +124,3 @@ where
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_cohort::ByAddressType;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
/// A vector for each address type.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_cohort::ByAddressType;
|
||||
use brk_types::{AnyAddressDataIndexEnum, LoadedAddressData, OutputType, TypeIndex};
|
||||
use vecdb::GenericStoredVec;
|
||||
|
||||
@@ -7,11 +7,11 @@ use crate::stateful::{
|
||||
compute::VecsReaders,
|
||||
};
|
||||
|
||||
use super::lookup::AddressLookup;
|
||||
use super::super::cohort::{
|
||||
update_tx_counts, EmptyAddressDataWithSource, LoadedAddressDataWithSource, TxIndexVec,
|
||||
WithAddressDataSource,
|
||||
EmptyAddressDataWithSource, LoadedAddressDataWithSource, TxIndexVec, WithAddressDataSource,
|
||||
update_tx_counts,
|
||||
};
|
||||
use super::lookup::AddressLookup;
|
||||
|
||||
/// Cache for address data within a flush interval.
|
||||
pub struct AddressCache {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::{AmountBucket, ByAddressType};
|
||||
use brk_cohort::{AmountBucket, ByAddressType};
|
||||
use brk_types::{Dollars, Sats, TypeIndex};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use brk_cohort::{AmountBucket, ByAddressType};
|
||||
use brk_error::Result;
|
||||
use brk_grouper::{AmountBucket, ByAddressType};
|
||||
use brk_types::{CheckedSub, Dollars, Height, Sats, Timestamp, TypeIndex};
|
||||
use vecdb::{VecIndex, unlikely};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_cohort::ByAddressType;
|
||||
use brk_types::{Height, OutputType, Sats, TxIndex, TypeIndex};
|
||||
use rayon::prelude::*;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_cohort::ByAddressType;
|
||||
use brk_types::{Sats, TxIndex, TypeIndex};
|
||||
|
||||
use crate::stateful::{
|
||||
address::{AddressTypeToTypeIndexMap, AddressTypeToVec, AddressesDataVecs, AnyAddressIndexesVecs},
|
||||
address::{
|
||||
AddressTypeToTypeIndexMap, AddressTypeToVec, AddressesDataVecs, AnyAddressIndexesVecs,
|
||||
},
|
||||
compute::{TxOutData, VecsReaders},
|
||||
state::Transacted,
|
||||
};
|
||||
|
||||
use super::super::{
|
||||
cache::{load_uncached_address_data, AddressCache},
|
||||
cache::{AddressCache, load_uncached_address_data},
|
||||
cohort::{LoadedAddressDataWithSource, TxIndexVec},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_grouper::{
|
||||
use brk_cohort::{
|
||||
AddressGroups, ByAmountRange, ByGreatEqualAmount, ByLowerThanAmount, Filter, Filtered,
|
||||
};
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Database, Exit, IterableVec};
|
||||
|
||||
use crate::{Indexes, indexes, price, stateful::DynCohortVecs};
|
||||
use crate::{ComputeIndexes, indexes, price, stateful::DynCohortVecs};
|
||||
|
||||
use crate::stateful::metrics::SupplyMetrics;
|
||||
|
||||
use super::{
|
||||
super::traits::CohortVecs,
|
||||
vecs::AddressCohortVecs,
|
||||
};
|
||||
use super::{super::traits::CohortVecs, vecs::AddressCohortVecs};
|
||||
|
||||
const VERSION: Version = Version::new(0);
|
||||
|
||||
@@ -41,11 +38,13 @@ impl AddressCohorts {
|
||||
let v = version + VERSION + Version::ZERO;
|
||||
|
||||
// Helper to create a cohort - only amount_range cohorts have state
|
||||
let create =
|
||||
|filter: Filter, name: &'static str, has_state: bool| -> Result<AddressCohortVecs> {
|
||||
let sp = if has_state { Some(states_path) } else { None };
|
||||
AddressCohortVecs::forced_import(db, filter, name, v, indexes, price, sp, all_supply)
|
||||
};
|
||||
let create = |filter: Filter,
|
||||
name: &'static str,
|
||||
has_state: bool|
|
||||
-> Result<AddressCohortVecs> {
|
||||
let sp = if has_state { Some(states_path) } else { None };
|
||||
AddressCohortVecs::forced_import(db, filter, name, v, indexes, price, sp, all_supply)
|
||||
};
|
||||
|
||||
let full = |f: Filter, name: &'static str| create(f, name, true);
|
||||
let none = |f: Filter, name: &'static str| create(f, name, false);
|
||||
@@ -62,7 +61,7 @@ impl AddressCohorts {
|
||||
/// For example, ">=1 BTC" cohort is computed from sum of amount_range cohorts that match.
|
||||
pub fn compute_overlapping_vecs(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let by_amount_range = &self.0.amount_range;
|
||||
@@ -111,7 +110,7 @@ impl AddressCohorts {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.par_iter_mut()
|
||||
@@ -124,7 +123,7 @@ impl AddressCohorts {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &S,
|
||||
height_to_market_cap: Option<&HM>,
|
||||
dateindex_to_market_cap: Option<&DM>,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_cohort::{CohortContext, Filter, Filtered};
|
||||
use brk_error::Result;
|
||||
use brk_grouper::{CohortContext, Filter, Filtered};
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, Height, StoredU64, Version};
|
||||
use rayon::prelude::*;
|
||||
@@ -11,7 +11,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
indexes, price,
|
||||
stateful::state::AddressCohortState,
|
||||
@@ -250,7 +250,7 @@ impl DynCohortVecs for AddressCohortVecs {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_addr_count.compute_rest(
|
||||
@@ -268,7 +268,7 @@ impl DynCohortVecs for AddressCohortVecs {
|
||||
impl CohortVecs for AddressCohortVecs {
|
||||
fn compute_from_stateful(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -293,7 +293,7 @@ impl CohortVecs for AddressCohortVecs {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &impl IterableVec<Height, Bitcoin>,
|
||||
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
|
||||
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
|
||||
use vecdb::{Exit, IterableVec};
|
||||
|
||||
use crate::{Indexes, indexes, price};
|
||||
use crate::{ComputeIndexes, indexes, price};
|
||||
|
||||
/// Dynamic dispatch trait for cohort vectors.
|
||||
///
|
||||
@@ -38,7 +38,7 @@ pub trait DynCohortVecs: Send + Sync {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()>;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ pub trait CohortVecs: DynCohortVecs {
|
||||
/// Compute aggregate cohort from component cohorts.
|
||||
fn compute_from_stateful(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()>;
|
||||
@@ -59,7 +59,7 @@ pub trait CohortVecs: DynCohortVecs {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &impl IterableVec<Height, Bitcoin>,
|
||||
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
|
||||
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_grouper::{
|
||||
use brk_cohort::{
|
||||
ByAgeRange, ByAmountRange, ByEpoch, ByGreatEqualAmount, ByLowerThanAmount, ByMaxAge, ByMinAge,
|
||||
BySpendableType, ByTerm, ByYear, Filter, Filtered, StateLevel, UTXOGroups,
|
||||
};
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Sats, Version};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
@@ -12,16 +12,13 @@ use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Database, Exit, IterableVec};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{PERCENTILES, PERCENTILES_LEN},
|
||||
indexes, price,
|
||||
stateful::DynCohortVecs,
|
||||
};
|
||||
|
||||
use super::{
|
||||
super::traits::CohortVecs,
|
||||
vecs::UTXOCohortVecs,
|
||||
};
|
||||
use super::{super::traits::CohortVecs, vecs::UTXOCohortVecs};
|
||||
|
||||
const VERSION: Version = Version::new(0);
|
||||
|
||||
@@ -59,7 +56,15 @@ impl UTXOCohorts {
|
||||
// Create all cohorts first (while borrowing all_supply), then assemble struct
|
||||
let price_only = |f: Filter, name: &'static str| {
|
||||
UTXOCohortVecs::forced_import(
|
||||
db, f, name, v, indexes, price, states_path, StateLevel::PriceOnly, all_supply,
|
||||
db,
|
||||
f,
|
||||
name,
|
||||
v,
|
||||
indexes,
|
||||
price,
|
||||
states_path,
|
||||
StateLevel::PriceOnly,
|
||||
all_supply,
|
||||
)
|
||||
};
|
||||
|
||||
@@ -67,12 +72,28 @@ impl UTXOCohorts {
|
||||
|
||||
let full = |f: Filter, name: &'static str| {
|
||||
UTXOCohortVecs::forced_import(
|
||||
db, f, name, v, indexes, price, states_path, StateLevel::Full, all_supply,
|
||||
db,
|
||||
f,
|
||||
name,
|
||||
v,
|
||||
indexes,
|
||||
price,
|
||||
states_path,
|
||||
StateLevel::Full,
|
||||
all_supply,
|
||||
)
|
||||
};
|
||||
let none = |f: Filter, name: &'static str| {
|
||||
UTXOCohortVecs::forced_import(
|
||||
db, f, name, v, indexes, price, states_path, StateLevel::None, all_supply,
|
||||
db,
|
||||
f,
|
||||
name,
|
||||
v,
|
||||
indexes,
|
||||
price,
|
||||
states_path,
|
||||
StateLevel::None,
|
||||
all_supply,
|
||||
)
|
||||
};
|
||||
|
||||
@@ -104,7 +125,7 @@ impl UTXOCohorts {
|
||||
/// Compute overlapping cohorts from component age/amount range cohorts.
|
||||
pub fn compute_overlapping_vecs(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let by_age_range = &self.0.age_range;
|
||||
@@ -172,7 +193,7 @@ impl UTXOCohorts {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.par_iter_mut()
|
||||
@@ -185,7 +206,7 @@ impl UTXOCohorts {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &S,
|
||||
height_to_market_cap: Option<&HM>,
|
||||
dateindex_to_market_cap: Option<&DM>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::AGE_BOUNDARIES;
|
||||
use brk_cohort::AGE_BOUNDARIES;
|
||||
use brk_types::{ONE_DAY_IN_SEC, Timestamp};
|
||||
|
||||
use crate::stateful::state::BlockState;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_cohort::{CohortContext, Filter, Filtered, StateLevel};
|
||||
use brk_error::Result;
|
||||
use brk_grouper::{CohortContext, Filter, Filtered, StateLevel};
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Database, Exit, IterableVec};
|
||||
|
||||
use crate::{Indexes, indexes, price, stateful::state::UTXOCohortState};
|
||||
use crate::{ComputeIndexes, indexes, price, stateful::state::UTXOCohortState};
|
||||
|
||||
use crate::stateful::metrics::{CohortMetrics, ImportConfig, SupplyMetrics};
|
||||
|
||||
@@ -211,7 +211,7 @@ impl DynCohortVecs for UTXOCohortVecs {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.metrics
|
||||
@@ -222,7 +222,7 @@ impl DynCohortVecs for UTXOCohortVecs {
|
||||
impl CohortVecs for UTXOCohortVecs {
|
||||
fn compute_from_stateful(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -237,7 +237,7 @@ impl CohortVecs for UTXOCohortVecs {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &impl IterableVec<Height, Bitcoin>,
|
||||
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
|
||||
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::{Bitcoin, DateIndex, Dollars, Height};
|
||||
use log::info;
|
||||
use vecdb::{Exit, IterableVec};
|
||||
|
||||
use crate::{Indexes, indexes, price};
|
||||
use crate::{ComputeIndexes, indexes, price};
|
||||
|
||||
use super::super::cohorts::{AddressCohorts, UTXOCohorts};
|
||||
|
||||
@@ -15,7 +15,7 @@ use super::super::cohorts::{AddressCohorts, UTXOCohorts};
|
||||
pub fn compute_overlapping(
|
||||
utxo_cohorts: &mut UTXOCohorts,
|
||||
address_cohorts: &mut AddressCohorts,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
info!("Computing overlapping cohorts...");
|
||||
@@ -34,7 +34,7 @@ pub fn compute_rest_part1(
|
||||
address_cohorts: &mut AddressCohorts,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
info!("Computing rest part 1...");
|
||||
@@ -54,7 +54,7 @@ pub fn compute_rest_part2<S, HM, DM>(
|
||||
address_cohorts: &mut AddressCohorts,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &S,
|
||||
height_to_market_cap: Option<&HM>,
|
||||
dateindex_to_market_cap: Option<&DM>,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::thread;
|
||||
|
||||
use brk_cohort::ByAddressType;
|
||||
use brk_error::Result;
|
||||
use brk_grouper::ByAddressType;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{DateIndex, Height, OutputType, Sats, TxIndex, TypeIndex};
|
||||
use log::info;
|
||||
@@ -12,11 +12,11 @@ use crate::{
|
||||
chain, indexes, price,
|
||||
stateful::{
|
||||
address::AddressTypeToAddressCount,
|
||||
compute::write::{process_address_updates, write},
|
||||
block::{
|
||||
AddressCache, InputsResult, process_inputs, process_outputs, process_received,
|
||||
process_sent,
|
||||
},
|
||||
compute::write::{process_address_updates, write},
|
||||
state::{BlockState, Transacted},
|
||||
},
|
||||
txins,
|
||||
@@ -63,10 +63,15 @@ pub fn process_blocks(
|
||||
|
||||
// From chain (via .height.u() or .height.unwrap_sum() patterns):
|
||||
let height_to_tx_count = chain.transaction.indexes_to_tx_count.height.u();
|
||||
let height_to_output_count = chain.transaction.indexes_to_output_count.height.unwrap_sum();
|
||||
let height_to_output_count = chain
|
||||
.transaction
|
||||
.indexes_to_output_count
|
||||
.height
|
||||
.unwrap_sum();
|
||||
let height_to_input_count = chain.transaction.indexes_to_input_count.height.unwrap_sum();
|
||||
let height_to_unclaimed_rewards = chain
|
||||
.coinbase.indexes_to_unclaimed_rewards
|
||||
.coinbase
|
||||
.indexes_to_unclaimed_rewards
|
||||
.sats
|
||||
.height
|
||||
.as_ref()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::{ByAddressType, ByAnyAddress};
|
||||
use brk_cohort::{ByAddressType, ByAnyAddress};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{
|
||||
Height, OutPoint, OutputType, Sats, StoredU64, TxInIndex, TxIndex, TxOutIndex, TypeIndex,
|
||||
@@ -9,7 +9,10 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
stateful::{address::{AddressesDataVecs, AnyAddressIndexesVecs}, RangeMap},
|
||||
stateful::{
|
||||
RangeMap,
|
||||
address::{AddressesDataVecs, AnyAddressIndexesVecs},
|
||||
},
|
||||
txins,
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{ComputedValueVecsFromHeight, ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
indexes, price,
|
||||
};
|
||||
@@ -143,7 +143,7 @@ impl ActivityMetrics {
|
||||
/// Compute aggregate values from separate cohorts.
|
||||
pub fn compute_from_stateful(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -176,7 +176,7 @@ impl ActivityMetrics {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_sent.compute_rest(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_grouper::{CohortContext, Filter};
|
||||
use brk_cohort::{CohortContext, Filter};
|
||||
use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ pub use realized::RealizedMetrics;
|
||||
pub use supply::SupplyMetrics;
|
||||
pub use unrealized::UnrealizedMetrics;
|
||||
|
||||
use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_grouper::Filter;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, Exit, IterableVec};
|
||||
|
||||
use crate::{Indexes, indexes, price as price_vecs, stateful::state::CohortState};
|
||||
use crate::{ComputeIndexes, indexes, price as price_vecs, stateful::state::CohortState};
|
||||
|
||||
/// All metrics for a cohort, organized by category.
|
||||
#[derive(Clone, Traversable)]
|
||||
@@ -205,7 +205,7 @@ impl CohortMetrics {
|
||||
/// Compute aggregate cohort values from separate cohorts.
|
||||
pub fn compute_from_stateful(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -261,7 +261,7 @@ impl CohortMetrics {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price_vecs::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.supply
|
||||
@@ -290,7 +290,7 @@ impl CohortMetrics {
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price_vecs::Vecs>,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
height_to_supply: &impl IterableVec<Height, Bitcoin>,
|
||||
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
|
||||
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Indexes,
|
||||
ComputeIndexes,
|
||||
grouped::{ComputedVecsFromHeight, PricePercentiles, Source, VecBuilderOptions},
|
||||
stateful::state::CohortState,
|
||||
};
|
||||
@@ -147,7 +147,7 @@ impl PricePaidMetrics {
|
||||
/// Compute aggregate values from separate cohorts.
|
||||
pub fn compute_from_stateful(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -174,7 +174,7 @@ impl PricePaidMetrics {
|
||||
pub fn compute_rest_part1(
|
||||
&mut self,
|
||||
indexes: &crate::indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_min_price_paid.compute_rest(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user