mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
@@ -27,11 +27,13 @@ impl Query {
|
||||
.day1;
|
||||
|
||||
Ok(iter.collect(|di, ts, h| {
|
||||
rewards_vec.collect_one_flat(di).map(|reward| BlockRewardsEntry {
|
||||
avg_height: h.into(),
|
||||
timestamp: *ts,
|
||||
avg_rewards: *reward,
|
||||
})
|
||||
rewards_vec
|
||||
.collect_one_flat(di)
|
||||
.map(|reward| BlockRewardsEntry {
|
||||
avg_height: h.into(),
|
||||
timestamp: *ts,
|
||||
avg_rewards: *reward,
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,12 @@ impl Query {
|
||||
let current_height = self.height();
|
||||
|
||||
// Get current difficulty
|
||||
let current_difficulty = *indexer.vecs.blocks.difficulty.collect_one(current_height).unwrap();
|
||||
let current_difficulty = *indexer
|
||||
.vecs
|
||||
.blocks
|
||||
.difficulty
|
||||
.collect_one(current_height)
|
||||
.unwrap();
|
||||
|
||||
// Get current hashrate
|
||||
let current_day1 = computer
|
||||
@@ -47,10 +52,7 @@ impl Query {
|
||||
let end_day1 = current_day1;
|
||||
|
||||
// Sample at regular intervals to avoid too many data points
|
||||
let total_days = end_day1
|
||||
.to_usize()
|
||||
.saturating_sub(start_day1.to_usize())
|
||||
+ 1;
|
||||
let total_days = end_day1.to_usize().saturating_sub(start_day1.to_usize()) + 1;
|
||||
let step = (total_days / 200).max(1); // Max ~200 data points
|
||||
|
||||
let hashrate_vec = &computer.mining.hashrate.hash_rate.day1;
|
||||
@@ -60,9 +62,10 @@ impl Query {
|
||||
let mut di = start_day1.to_usize();
|
||||
while di <= end_day1.to_usize() {
|
||||
let day1 = Day1::from(di);
|
||||
if let (Some(hr), Some(timestamp)) =
|
||||
(hashrate_vec.collect_one_flat(day1), timestamp_vec.collect_one(day1))
|
||||
{
|
||||
if let (Some(hr), Some(timestamp)) = (
|
||||
hashrate_vec.collect_one_flat(day1),
|
||||
timestamp_vec.collect_one(day1),
|
||||
) {
|
||||
hashrates.push(HashrateEntry {
|
||||
timestamp,
|
||||
avg_hashrate: *hr as u128,
|
||||
|
||||
@@ -30,16 +30,16 @@ impl Query {
|
||||
|
||||
// For each pool, get cumulative count at end and start, subtract to get range count
|
||||
for (pool_id, pool_vecs) in &computer.pools.vecs {
|
||||
let cumulative = &pool_vecs
|
||||
.blocks_mined
|
||||
.cumulative.height;
|
||||
let cumulative = &pool_vecs.blocks_mined.cumulative.height;
|
||||
|
||||
let count_at_end: u32 = *cumulative.collect_one(current_height).unwrap_or_default();
|
||||
|
||||
let count_at_start: u32 = if start == 0 {
|
||||
0
|
||||
} else {
|
||||
*cumulative.collect_one(Height::from(start - 1)).unwrap_or_default()
|
||||
*cumulative
|
||||
.collect_one(Height::from(start - 1))
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
let block_count = count_at_end.saturating_sub(count_at_start);
|
||||
@@ -98,9 +98,7 @@ impl Query {
|
||||
.get(&slug)
|
||||
.ok_or_else(|| Error::NotFound("Pool data not found".into()))?;
|
||||
|
||||
let cumulative = &pool_vecs
|
||||
.blocks_mined
|
||||
.cumulative.height;
|
||||
let cumulative = &pool_vecs.blocks_mined.cumulative.height;
|
||||
|
||||
// Get total blocks (all time)
|
||||
let total_all: u32 = *cumulative.collect_one(current_height).unwrap_or_default();
|
||||
|
||||
Reference in New Issue
Block a user