mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-02 06:48:59 -07:00
app: add height datasets
This commit is contained in:
@@ -61,14 +61,10 @@ pub fn parse(
|
||||
|
||||
let date_index = states.date_data_vec.len() - 1;
|
||||
|
||||
let previous_timestamp = if let Some(previous_height) = height.checked_sub(1) {
|
||||
datasets
|
||||
.block_metadata
|
||||
.timestamp
|
||||
.get_or_import(&Height::new(previous_height))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let previous_timestamp = height
|
||||
.checked_sub(1)
|
||||
.map(Height::new)
|
||||
.and_then(|height| datasets.block_metadata.timestamp.get_or_import(&height));
|
||||
|
||||
let block_price = Price::from_dollar(
|
||||
datasets
|
||||
@@ -91,7 +87,7 @@ pub fn parse(
|
||||
let block_weight = block.weight().to_wu();
|
||||
let block_vbytes = block.weight().to_vbytes_floor();
|
||||
let block_interval = previous_timestamp.map_or(0, |previous_timestamp| {
|
||||
if previous_timestamp <= timestamp {
|
||||
if previous_timestamp >= timestamp {
|
||||
0
|
||||
} else {
|
||||
timestamp - previous_timestamp
|
||||
|
||||
@@ -185,6 +185,7 @@ impl MiningDataset {
|
||||
block_size_recap: RecapDataset::import(
|
||||
&f("block_size_1d"),
|
||||
RecapOptions::default()
|
||||
.add_sum()
|
||||
.add_average()
|
||||
.add_max()
|
||||
.add_90p()
|
||||
@@ -548,7 +549,12 @@ impl MiningDataset {
|
||||
|
||||
self.block_size_recap.compute(
|
||||
*date,
|
||||
&mut self.block_vbytes.get_or_import_range_inclusive(first, last),
|
||||
&mut self
|
||||
.block_size
|
||||
.get_or_import_range_inclusive(first, last)
|
||||
.into_iter()
|
||||
.map(OrderedFloat)
|
||||
.collect_vec(),
|
||||
);
|
||||
|
||||
self.block_weight_recap.compute(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{collections::BTreeMap, ops::RangeInclusive};
|
||||
use std::{collections::BTreeMap, fs, ops::RangeInclusive};
|
||||
|
||||
use allocative::Allocative;
|
||||
|
||||
@@ -140,7 +140,7 @@ impl AllDatasets {
|
||||
s.min_initial_states
|
||||
.consume(MinInitialStates::compute_from_datasets(&s));
|
||||
|
||||
s.export_path_to_type()?;
|
||||
s.export_meta_files()?;
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
@@ -263,7 +263,7 @@ impl AllDatasets {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn export_path_to_type(&self) -> color_eyre::Result<()> {
|
||||
pub fn export_meta_files(&self) -> color_eyre::Result<()> {
|
||||
let path_to_type: BTreeMap<&str, &str> = self
|
||||
.to_any_dataset_vec()
|
||||
.into_iter()
|
||||
@@ -275,7 +275,27 @@ impl AllDatasets {
|
||||
})
|
||||
.collect();
|
||||
|
||||
Json::export("../datasets/disk_path_to_type.json", &path_to_type)
|
||||
let datasets_len = path_to_type.len();
|
||||
|
||||
Json::export("../datasets/disk_path_to_type.json", &path_to_type)?;
|
||||
|
||||
let server_trigger_path = "../server/.trigger";
|
||||
|
||||
fs::create_dir_all(server_trigger_path)?;
|
||||
|
||||
let datasets_len_path = format!("{server_trigger_path}/datasets_len.txt");
|
||||
|
||||
if let Ok(len) = fs::read_to_string(&datasets_len_path) {
|
||||
if let Ok(len) = len.parse::<usize>() {
|
||||
if datasets_len == len {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs::write(datasets_len_path, datasets_len.to_string())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn export(&mut self) -> color_eyre::Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user