mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: v0.2 incoming
This commit is contained in:
@@ -151,7 +151,7 @@ fn fill_mixed_empty_field_parts(
|
||||
&& let Some(suffix) = leaf.strip_prefix(&prefix)
|
||||
&& !suffix.is_empty()
|
||||
&& suffix.contains(field_name.trim_start_matches('_'))
|
||||
&& suffix.len() > field_name.trim_start_matches('_').len()
|
||||
&& suffix.len() >= field_name.trim_start_matches('_').len()
|
||||
{
|
||||
updates.push((field_name.clone(), suffix.to_string()));
|
||||
}
|
||||
@@ -485,19 +485,21 @@ fn determine_pattern_mode(
|
||||
) -> Option<PatternMode> {
|
||||
analyses.first()?;
|
||||
|
||||
// If any instance has outlier naming (no common prefix/suffix among children),
|
||||
// the pattern can't be parameterized.
|
||||
if analyses.iter().any(|a| a.has_outlier) {
|
||||
// Filter out outlier instances — they'll be inlined individually at generation
|
||||
// time via the per-instance has_outlier check in prepare_tree_node.
|
||||
// Don't let a single outlier poison the entire pattern.
|
||||
let non_outlier: Vec<&InstanceAnalysis> = analyses.iter().filter(|a| !a.has_outlier).collect();
|
||||
if non_outlier.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Pick the majority mode
|
||||
let suffix_count = analyses.iter().filter(|a| a.is_suffix_mode).count();
|
||||
let is_suffix = suffix_count * 2 >= analyses.len();
|
||||
let suffix_count = non_outlier.iter().filter(|a| a.is_suffix_mode).count();
|
||||
let is_suffix = suffix_count * 2 >= non_outlier.len();
|
||||
|
||||
// All instances of the majority mode must agree on field_parts
|
||||
let majority: Vec<_> = analyses
|
||||
.iter()
|
||||
let majority: Vec<&InstanceAnalysis> = non_outlier
|
||||
.into_iter()
|
||||
.filter(|a| a.is_suffix_mode == is_suffix)
|
||||
.collect();
|
||||
let first_majority = majority.first()?;
|
||||
|
||||
@@ -68,6 +68,10 @@ fn generate_tree_class(
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if ctx.children.is_empty() {
|
||||
writeln!(output, " pass").unwrap();
|
||||
}
|
||||
|
||||
let syntax = PythonSyntax;
|
||||
for child in &ctx.children {
|
||||
if child.is_leaf {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPointsSigned32, Height, Indexes, StoredF32, StoredI64, StoredU32, StoredU64, Version};
|
||||
use brk_types::{
|
||||
BasisPointsSigned32, Height, Indexes, StoredF32, StoredI64, StoredU32, StoredU64, Version,
|
||||
};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{
|
||||
@@ -8,7 +10,7 @@ use crate::{
|
||||
metrics::ImportConfig,
|
||||
state::{CohortState, CostBasisOps, RealizedOps},
|
||||
},
|
||||
internal::{PerBlock, PerBlockCumulativeRolling, PerBlockWithDeltas, RatioU32U64F32},
|
||||
internal::{PerBlock, PerBlockCumulativeRolling, PerBlockWithDeltas, RatioU64F32},
|
||||
};
|
||||
|
||||
/// Base output metrics: utxo_count + delta.
|
||||
@@ -32,12 +34,14 @@ impl OutputsBase {
|
||||
cfg.cached_starts,
|
||||
)?,
|
||||
spent_count: cfg.import("spent_utxo_count", v1)?,
|
||||
spending_rate: cfg.import("spending_rate", v1)?,
|
||||
spending_rate: cfg.import("spending_rate", Version::TWO)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn min_len(&self) -> usize {
|
||||
self.unspent_count.height.len()
|
||||
self.unspent_count
|
||||
.height
|
||||
.len()
|
||||
.min(self.spent_count.block.len())
|
||||
}
|
||||
|
||||
@@ -69,9 +73,9 @@ impl OutputsBase {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.spending_rate
|
||||
.compute_binary::<StoredU32, StoredU64, RatioU32U64F32>(
|
||||
.compute_binary::<StoredU64, StoredU64, RatioU64F32>(
|
||||
max_from,
|
||||
&self.spent_count.block,
|
||||
&self.spent_count.sum.0._1y.height,
|
||||
all_utxo_count,
|
||||
exit,
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ pub use derived::{
|
||||
pub use ratio::{
|
||||
RatioCentsBp32, RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDiffCentsBps32,
|
||||
RatioDiffDollarsBps32, RatioDiffF32Bps32, RatioDollarsBp16, RatioDollarsBp32,
|
||||
RatioDollarsBps32, RatioSatsBp16, RatioU32U64F32, RatioU64Bp16,
|
||||
RatioDollarsBps32, RatioSatsBp16, RatioU64Bp16, RatioU64F32,
|
||||
};
|
||||
pub use specialized::{
|
||||
BlockCountTarget1m, BlockCountTarget1w, BlockCountTarget1y, BlockCountTarget24h,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_types::{
|
||||
BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, CentsSigned, Dollars, Sats, StoredF32,
|
||||
StoredU32, StoredU64,
|
||||
StoredU64,
|
||||
};
|
||||
use vecdb::BinaryTransform;
|
||||
|
||||
@@ -112,11 +112,11 @@ impl BinaryTransform<Dollars, Dollars, BasisPoints32> for RatioDollarsBp32 {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RatioU32U64F32;
|
||||
pub struct RatioU64F32;
|
||||
|
||||
impl BinaryTransform<StoredU32, StoredU64, StoredF32> for RatioU32U64F32 {
|
||||
impl BinaryTransform<StoredU64, StoredU64, StoredF32> for RatioU64F32 {
|
||||
#[inline(always)]
|
||||
fn apply(numerator: StoredU32, denominator: StoredU64) -> StoredF32 {
|
||||
fn apply(numerator: StoredU64, denominator: StoredU64) -> StoredF32 {
|
||||
if *denominator > 0 {
|
||||
StoredF32::from(*numerator as f64 / *denominator as f64)
|
||||
} else {
|
||||
|
||||
@@ -309,10 +309,16 @@ fn gen_traversable(input: &DeriveInput) -> proc_macro2::TokenStream {
|
||||
&field_traversable_types,
|
||||
);
|
||||
|
||||
let to_tree_node_body = if struct_attr.hidden {
|
||||
quote! { brk_traversable::TreeNode::Branch(brk_traversable::IndexMap::new()) }
|
||||
} else {
|
||||
field_traversals
|
||||
};
|
||||
|
||||
quote! {
|
||||
impl #impl_generics Traversable for #name #ty_generics #where_clause {
|
||||
fn to_tree_node(&self) -> brk_traversable::TreeNode {
|
||||
#field_traversals
|
||||
#to_tree_node_body
|
||||
}
|
||||
|
||||
#iterator_impl
|
||||
|
||||
Reference in New Issue
Block a user