computer: indexes + rolling

This commit is contained in:
nym21
2026-02-24 17:07:35 +01:00
parent cefc8cfd42
commit f74115c6e2
160 changed files with 2604 additions and 4739 deletions

View File

@@ -1,5 +1,5 @@
use brk_error::Result;
use brk_types::{BlockFeesEntry, TimePeriod};
use brk_types::{BlockFeesEntry, Height, Sats, TimePeriod};
use vecdb::{ReadableVec, VecIndex};
use super::day1_iter::Day1Iter;
@@ -15,19 +15,32 @@ impl Query {
let iter = Day1Iter::new(computer, start, current_height.to_usize());
let fees_vec = &computer
.transactions
.fees
.fee
.sats
.day1
.average;
let cumulative = &computer.transactions.fees.fee.sum_cum.cumulative;
let first_height = &computer.indexes.day1.first_height;
Ok(iter.collect(|di, ts, h| {
fees_vec.collect_one(di).map(|fee| BlockFeesEntry {
let h_start = first_height.collect_one(di)?;
let h_end = first_height
.collect_one(di + 1_usize)
.unwrap_or(Height::from(current_height.to_usize() + 1));
let block_count = h_end.to_usize() - h_start.to_usize();
if block_count == 0 {
return None;
}
let cum_end = cumulative.collect_one_at(h_end.to_usize() - 1)?;
let cum_start = if h_start.to_usize() > 0 {
cumulative.collect_one_at(h_start.to_usize() - 1).unwrap_or(Sats::ZERO)
} else {
Sats::ZERO
};
let daily_sum = cum_end - cum_start;
let avg_fees = Sats::from(*daily_sum / block_count as u64);
Some(BlockFeesEntry {
avg_height: h,
timestamp: ts,
avg_fees: fee,
avg_fees,
})
}))
}

View File

@@ -15,28 +15,35 @@ impl Query {
let iter = Day1Iter::new(computer, start, current_height.to_usize());
// Rolling 24h average, sampled at day1 boundaries
let sizes_vec = &computer
.blocks
.size
.size
.day1
.average;
.rolling
.distribution
.average
._24h
.day1;
let weights_vec = &computer
.blocks
.weight
.weight
.day1
.average;
.rolling
.distribution
.average
._24h
.day1;
let entries: Vec<_> = iter.collect(|di, ts, h| {
let size = sizes_vec.collect_one(di).map(|s| *s);
let weight = weights_vec.collect_one(di).map(|w| *w);
Some((h.into(), (*ts), size, weight))
let size: Option<u64> = sizes_vec.collect_one(di).map(|s| *s);
let weight: Option<u64> = weights_vec.collect_one(di).map(|w| *w);
Some((u32::from(h), (*ts), size, weight))
});
let sizes = entries
.iter()
.filter_map(|(h, ts, size, _): &(u32, _, _, _)| {
.filter_map(|(h, ts, size, _)| {
size.map(|s| BlockSizeEntry {
avg_height: *h,
timestamp: *ts,
@@ -47,7 +54,7 @@ impl Query {
let weights = entries
.iter()
.filter_map(|(h, ts, _, weight): &(u32, _, _, _)| {
.filter_map(|(h, ts, _, weight)| {
weight.map(|w| BlockWeightEntry {
avg_height: *h,
timestamp: *ts,

View File

@@ -13,7 +13,7 @@ impl Query {
let start_block = Height::from(current_height.to_usize().saturating_sub(block_count - 1));
let coinbase_vec = &computer.mining.rewards.coinbase.sats.height;
let fee_vec = &computer.transactions.fees.fee.sats.height.sum_cum.sum.0;
let fee_vec = &computer.transactions.fees.fee.sum_cum.sum.0;
let tx_count_vec = &computer.transactions.count.tx_count.height;
let start = start_block.to_usize();