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,
})
}))
}