general: snapshot

This commit is contained in:
k
2024-07-20 23:13:41 +02:00
parent d8a5b4a2e6
commit a145b35ad1
100 changed files with 5402 additions and 2967 deletions

View File

@@ -3,7 +3,7 @@ use rayon::prelude::*;
use crate::{
datasets::ComputeData,
structs::{AnyBiMap, AnyDateMap, AnyHeightMap, AnyMap, WNaiveDate},
structs::{AnyBiMap, AnyDateMap, AnyHeightMap, AnyMap, Date, Height},
};
use super::MinInitialStates;
@@ -11,23 +11,23 @@ use super::MinInitialStates;
pub trait AnyDataset {
fn get_min_initial_states(&self) -> &MinInitialStates;
fn needs_insert(&self, height: usize, date: WNaiveDate) -> bool {
fn needs_insert(&self, height: Height, date: Date) -> bool {
self.needs_insert_height(height) || self.needs_insert_date(date)
}
#[inline(always)]
fn needs_insert_height(&self, height: usize) -> bool {
fn needs_insert_height(&self, height: Height) -> bool {
!self.to_all_inserted_height_map_vec().is_empty()
&& self
.get_min_initial_states()
.inserted
.first_unsafe_height
.unwrap_or(0)
.unwrap_or(Height::ZERO)
<= height
}
#[inline(always)]
fn needs_insert_date(&self, date: WNaiveDate) -> bool {
fn needs_insert_date(&self, date: Date) -> bool {
!self.to_all_inserted_date_map_vec().is_empty()
&& self
.get_min_initial_states()
@@ -117,18 +117,18 @@ pub trait AnyDataset {
}
#[inline(always)]
fn should_compute_height(&self, height: usize) -> bool {
fn should_compute_height(&self, height: Height) -> bool {
!self.to_all_computed_height_map_vec().is_empty()
&& self
.get_min_initial_states()
.computed
.first_unsafe_height
.unwrap_or(0)
.unwrap_or(Height::ZERO)
<= height
}
#[inline(always)]
fn should_compute_date(&self, date: WNaiveDate) -> bool {
fn should_compute_date(&self, date: Date) -> bool {
!self.to_all_computed_date_map_vec().is_empty()
&& self
.get_min_initial_states()

View File

@@ -1,6 +1,6 @@
use allocative::Allocative;
use crate::structs::{AnyDateMap, AnyHeightMap, WNaiveDate};
use crate::structs::{AnyDateMap, AnyHeightMap, Date, Height};
use super::{AnyDataset, AnyDatasets};
@@ -33,10 +33,10 @@ impl MinInitialStates {
#[derive(Default, Debug, Clone, Copy, Allocative)]
pub struct MinInitialState {
pub first_unsafe_date: Option<WNaiveDate>,
pub first_unsafe_height: Option<usize>,
pub last_date: Option<WNaiveDate>,
pub last_height: Option<usize>,
pub first_unsafe_date: Option<Date>,
pub first_unsafe_height: Option<Height>,
pub last_date: Option<Date>,
pub last_height: Option<Height>,
}
enum Mode {
@@ -172,8 +172,8 @@ impl MinInitialState {
fn min_datasets_date(
datasets: &dyn AnyDatasets,
is_not_empty: impl Fn(&&(dyn AnyDataset + Sync + Send)) -> bool,
map: impl Fn(&(dyn AnyDataset + Sync + Send)) -> Option<WNaiveDate>,
) -> Option<WNaiveDate> {
map: impl Fn(&(dyn AnyDataset + Sync + Send)) -> Option<Date>,
) -> Option<Date> {
Self::min_date(
datasets
.to_any_dataset_vec()
@@ -186,8 +186,8 @@ impl MinInitialState {
fn min_datasets_height(
datasets: &dyn AnyDatasets,
is_not_empty: impl Fn(&&(dyn AnyDataset + Sync + Send)) -> bool,
map: impl Fn(&(dyn AnyDataset + Sync + Send)) -> Option<usize>,
) -> Option<usize> {
map: impl Fn(&(dyn AnyDataset + Sync + Send)) -> Option<Height>,
) -> Option<Height> {
Self::min_height(
datasets
.to_any_dataset_vec()
@@ -235,38 +235,38 @@ impl MinInitialState {
#[inline(always)]
fn compute_min_initial_last_date_from_dataset(
arr: &[&(dyn AnyDateMap + Sync + Send)],
) -> Option<WNaiveDate> {
) -> Option<Date> {
Self::min_date(arr.iter().map(|map| map.get_initial_last_date()))
}
#[inline(always)]
fn compute_min_initial_last_height_from_dataset(
arr: &[&(dyn AnyHeightMap + Sync + Send)],
) -> Option<usize> {
) -> Option<Height> {
Self::min_height(arr.iter().map(|map| map.get_initial_last_height()))
}
#[inline(always)]
fn compute_min_initial_first_unsafe_date_from_dataset(
arr: &[&(dyn AnyDateMap + Sync + Send)],
) -> Option<WNaiveDate> {
) -> Option<Date> {
Self::min_date(arr.iter().map(|map| map.get_initial_first_unsafe_date()))
}
#[inline(always)]
fn compute_min_initial_first_unsafe_height_from_dataset(
arr: &[&(dyn AnyHeightMap + Sync + Send)],
) -> Option<usize> {
) -> Option<Height> {
Self::min_height(arr.iter().map(|map| map.get_initial_first_unsafe_height()))
}
#[inline(always)]
fn min_date(iter: impl Iterator<Item = Option<WNaiveDate>>) -> Option<WNaiveDate> {
fn min_date(iter: impl Iterator<Item = Option<Date>>) -> Option<Date> {
iter.min().and_then(|opt| opt)
}
#[inline(always)]
fn min_height(iter: impl Iterator<Item = Option<usize>>) -> Option<usize> {
fn min_height(iter: impl Iterator<Item = Option<Height>>) -> Option<Height> {
iter.min().and_then(|opt| opt)
}
}

View File

@@ -62,7 +62,7 @@ impl AllAddressesMetadataDataset {
}
}
pub fn compute(&mut self, &ComputeData { heights, dates }: &ComputeData) {
pub fn compute(&mut self, &ComputeData { heights, dates, .. }: &ComputeData) {
self.new_addresses
.multi_insert_net_change(heights, dates, &mut self.created_addreses, 1)
}

View File

@@ -6,7 +6,7 @@ use crate::{
AnyDataset, AnyDatasetGroup, ComputeData, InsertData, MinInitialStates, SubDataset,
},
states::{AddressCohortDurableStates, AddressCohortId},
structs::{AddressSplit, AnyBiMap, AnyDateMap, AnyHeightMap, BiMap, WNaiveDate},
structs::{AddressSplit, AnyBiMap, AnyDateMap, AnyHeightMap, BiMap, Date, Height},
};
use super::cohort_metadata::MetadataDataset;
@@ -60,47 +60,47 @@ impl CohortDataset {
vec![&self.all, &self.illiquid, &self.liquid, &self.highly_liquid]
}
pub fn needs_insert_metadata(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_metadata(&self, height: Height, date: Date) -> bool {
self.metadata.needs_insert(height, date)
}
pub fn needs_insert_utxo(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_utxo(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.utxo.needs_insert(height, date))
}
pub fn needs_insert_capitalization(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_capitalization(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.capitalization.needs_insert(height, date))
}
pub fn needs_insert_supply(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_supply(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.supply.needs_insert(height, date))
}
pub fn needs_insert_price_paid(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_price_paid(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.price_paid.needs_insert(height, date))
}
pub fn needs_insert_realized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_realized(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.realized.needs_insert(height, date))
}
pub fn needs_insert_unrealized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_unrealized(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.unrealized.needs_insert(height, date))
}
pub fn needs_insert_input(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_input(&self, height: Height, date: Date) -> bool {
self.sub_datasets_vec()
.iter()
.any(|sub| sub.input.needs_insert(height, date))

View File

@@ -6,7 +6,11 @@ use allocative::Allocative;
use itertools::Itertools;
use rayon::prelude::*;
use crate::{states::SplitByAddressCohort, structs::BiMap, WNaiveDate};
use crate::{
states::SplitByAddressCohort,
structs::{BiMap, Height},
Date,
};
use self::{all_metadata::AllAddressesMetadataDataset, cohort::CohortDataset};
@@ -59,7 +63,7 @@ impl AddressDatasets {
.for_each(|(cohort, _)| cohort.insert(insert_data))
}
pub fn needs_durable_states(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_durable_states(&self, height: Height, date: Date) -> bool {
let needs_insert_utxo = self.needs_insert_utxo(height, date);
let needs_insert_capitalization = self.needs_insert_capitalization(height, date);
let needs_insert_supply = self.needs_insert_supply(height, date);
@@ -71,57 +75,57 @@ impl AddressDatasets {
|| needs_one_shot_states
}
pub fn needs_one_shot_states(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_one_shot_states(&self, height: Height, date: Date) -> bool {
self.needs_insert_price_paid(height, date) || self.needs_insert_unrealized(height, date)
}
// pub fn needs_sent_states(&self, height: usize, date: WNaiveDate) -> bool {
// pub fn needs_sent_states(&self, height: Height, date: WNaiveDate) -> bool {
// self.needs_insert_input(height, date) || self.needs_insert_realized(height, date)
// }
pub fn needs_insert_utxo(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_utxo(&self, height: Height, date: Date) -> bool {
self.cohorts
.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_utxo(height, date))
}
pub fn needs_insert_capitalization(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_capitalization(&self, height: Height, date: Date) -> bool {
self.cohorts
.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_capitalization(height, date))
}
pub fn needs_insert_supply(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_supply(&self, height: Height, date: Date) -> bool {
self.cohorts
.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_supply(height, date))
}
pub fn needs_insert_price_paid(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_price_paid(&self, height: Height, date: Date) -> bool {
self.cohorts
.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_price_paid(height, date))
}
// pub fn needs_insert_realized(&self, height: usize, date: WNaiveDate) -> bool {
// pub fn needs_insert_realized(&self, height: Height, date: WNaiveDate) -> bool {
// self.cohorts
// .as_vec()
// .iter()
// .any(|(dataset, _)| dataset.needs_insert_realized(height, date))
// }
pub fn needs_insert_unrealized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_unrealized(&self, height: Height, date: Date) -> bool {
self.cohorts
.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_unrealized(height, date))
}
// pub fn needs_insert_input(&self, height: usize, date: WNaiveDate) -> bool {
// pub fn needs_insert_input(&self, height: Height, date: WNaiveDate) -> bool {
// self.cohorts
// .as_vec()
// .iter()

View File

@@ -2,7 +2,7 @@ use allocative::Allocative;
use crate::{
datasets::AnyDataset,
structs::{AnyHeightMap, HeightMap, WNaiveDate},
structs::{AnyHeightMap, Date, HeightMap},
};
use super::{InsertData, MinInitialStates};
@@ -12,7 +12,7 @@ pub struct BlockMetadataDataset {
min_initial_states: MinInitialStates,
// Inserted
pub date: HeightMap<WNaiveDate>,
pub date: HeightMap<Date>,
pub timestamp: HeightMap<u32>,
}
@@ -41,8 +41,7 @@ impl BlockMetadataDataset {
) {
self.timestamp.insert(height, timestamp);
self.date
.insert(height, WNaiveDate::from_timestamp(timestamp));
self.date.insert(height, Date::from_timestamp(timestamp));
}
}

View File

@@ -1,7 +1,7 @@
use allocative::Allocative;
use crate::{
structs::{AnyBiMap, BiMap, DateMap},
structs::{AnyBiMap, BiMap, DateMap, Height},
utils::{ONE_DAY_IN_DAYS, ONE_YEAR_IN_DAYS, THREE_MONTHS_IN_DAYS, TWO_WEEK_IN_DAYS},
};
@@ -166,8 +166,8 @@ impl CointimeDataset {
pub fn compute(
&mut self,
compute_data: &ComputeData,
first_height: &mut DateMap<usize>,
last_height: &mut DateMap<usize>,
first_height: &mut DateMap<Height>,
last_height: &mut DateMap<Height>,
closes: &mut BiMap<f32>,
circulating_supply: &mut BiMap<f64>,
realized_cap: &mut BiMap<f32>,
@@ -176,7 +176,7 @@ impl CointimeDataset {
annualized_transaction_volume: &mut BiMap<f32>,
cumulative_subsidy_in_dollars: &mut BiMap<f32>,
) {
let &ComputeData { heights, dates } = compute_data;
let &ComputeData { heights, dates, .. } = compute_data;
self.cumulative_coinblocks_destroyed
.multi_insert_cumulative(heights, dates, &mut self.coinblocks_destroyed);
@@ -403,7 +403,7 @@ impl CointimeDataset {
.multi_insert_complex_transform(
heights,
&mut self.active_cap.height,
|(active_cap, height)| {
|(active_cap, height, ..)| {
let investor_cap = self.investor_cap.height.get(height).unwrap();
(active_cap - investor_cap) / active_cap

View File

@@ -34,7 +34,7 @@ impl ConstantDataset {
Ok(s)
}
pub fn compute(&mut self, &ComputeData { heights, dates }: &ComputeData) {
pub fn compute(&mut self, &ComputeData { heights, dates, .. }: &ComputeData) {
self._0.multi_insert_const(heights, dates, 0);
self._1.multi_insert_const(heights, dates, 1);
self._50.multi_insert_const(heights, dates, 50);

View File

@@ -2,7 +2,7 @@ use allocative::Allocative;
use crate::{
datasets::AnyDataset,
structs::{AnyDateMap, DateMap},
structs::{AnyDateMap, DateMap, Height},
};
use super::{InsertData, MinInitialStates};
@@ -12,8 +12,8 @@ pub struct DateMetadataDataset {
min_initial_states: MinInitialStates,
// Inserted
pub first_height: DateMap<usize>,
pub last_height: DateMap<usize>,
pub first_height: DateMap<Height>,
pub last_height: DateMap<Height>,
}
impl DateMetadataDataset {

View File

@@ -3,7 +3,9 @@ use allocative::Allocative;
use crate::{
bitcoin::TARGET_BLOCKS_PER_DAY,
datasets::AnyDataset,
structs::{AnyBiMap, AnyDateMap, AnyHeightMap, BiMap, DateMap, HeightMap, WAmount},
structs::{
Amount, AnyBiMap, AnyDateMap, AnyHeightMap, BiMap, DateMap, Height, HeightMap, MapKey,
},
utils::{BYTES_IN_MB, ONE_DAY_IN_DAYS, ONE_MONTH_IN_DAYS, ONE_WEEK_IN_DAYS, ONE_YEAR_IN_DAYS},
};
@@ -224,7 +226,7 @@ impl MiningDataset {
.height
.insert(height, (block_price * coinbase).to_dollar() as f32);
let sumed_fees = WAmount::from_sat(fees.iter().map(|amount| amount.to_sat()).sum());
let sumed_fees = Amount::from_sat(fees.iter().map(|amount| amount.to_sat()).sum());
self.fees.height.insert(height, sumed_fees.to_btc());
@@ -281,10 +283,10 @@ impl MiningDataset {
self.last_fees_in_dollars
.insert(date, sumed_fees_in_dollars);
let total_blocks_mined = self.total_blocks_mined.insert(date, height + 1);
let total_blocks_mined = self.total_blocks_mined.insert(date, height.to_usize() + 1);
self.blocks_mined
.insert(date, total_blocks_mined - date_first_height);
.insert(date, total_blocks_mined - date_first_height.to_usize());
self.difficulty.date.insert(date, difficulty);
}
@@ -292,8 +294,8 @@ impl MiningDataset {
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
last_height: &mut DateMap<usize>,
&ComputeData { heights, dates, .. }: &ComputeData,
last_height: &mut DateMap<Height>,
) {
self.blocks_mined_1w_sum.multi_insert_last_x_sum(
dates,

View File

@@ -44,31 +44,31 @@ use crate::{
// UTXOCohortsReceivedStates,
UTXOCohortsSentStates,
},
structs::{Price, WAmount, WNaiveDate},
structs::{Amount, Date, Height, Price},
};
pub struct InsertData<'a> {
pub address_cohorts_input_states: &'a Option<AddressCohortsInputStates>,
pub address_cohorts_one_shot_states: &'a Option<AddressCohortsOneShotStates>,
pub address_cohorts_realized_states: &'a Option<AddressCohortsRealizedStates>,
pub amount_sent: WAmount,
pub amount_sent: Amount,
pub block_interval: u32,
pub block_price: Price,
pub block_size: usize,
pub block_vbytes: u64,
pub block_weight: u64,
pub coinbase: WAmount,
pub coinbase: Amount,
pub compute_addresses: bool,
pub databases: &'a Databases,
pub date: WNaiveDate,
pub date_blocks_range: &'a RangeInclusive<usize>,
pub date_first_height: usize,
pub date: Date,
pub date_blocks_range: &'a RangeInclusive<u32>,
pub date_first_height: Height,
pub difficulty: f64,
pub fees: &'a Vec<WAmount>,
pub height: usize,
pub fees: &'a Vec<Amount>,
pub height: Height,
pub is_date_last_block: bool,
pub satblocks_destroyed: WAmount,
pub satdays_destroyed: WAmount,
pub satblocks_destroyed: Amount,
pub satdays_destroyed: Amount,
pub states: &'a States,
pub timestamp: u32,
pub transaction_count: usize,
@@ -78,8 +78,8 @@ pub struct InsertData<'a> {
}
pub struct ComputeData<'a> {
pub heights: &'a [usize],
pub dates: &'a [WNaiveDate],
pub heights: &'a [Height],
pub dates: &'a [Date],
}
#[derive(Allocative)]

View File

@@ -10,7 +10,7 @@ pub use ohlc::*;
use crate::{
price::{Binance, Kraken},
structs::{AnyBiMap, AnyDateMap, BiMap, DateMap, WNaiveDate},
structs::{AnyBiMap, AnyDateMap, BiMap, Date, DateMap, Height, MapKey},
utils::{ONE_MONTH_IN_DAYS, ONE_WEEK_IN_DAYS, ONE_YEAR_IN_DAYS},
};
@@ -20,7 +20,7 @@ use super::{AnyDataset, ComputeData, MinInitialStates, RatioDataset};
pub struct PriceDatasets {
min_initial_states: MinInitialStates,
kraken_daily: Option<BTreeMap<WNaiveDate, OHLC>>,
kraken_daily: Option<BTreeMap<Date, OHLC>>,
kraken_1mn: Option<BTreeMap<u32, OHLC>>,
binance_1mn: Option<BTreeMap<u32, OHLC>>,
binance_har: Option<BTreeMap<u32, OHLC>>,
@@ -90,8 +90,8 @@ impl PriceDatasets {
kraken_daily: None,
satonomics_by_height: BTreeMap::default(),
ohlcs: BiMap::new_json(1, &format!("{price_path}/ohlc")),
closes: BiMap::new_json(1, &f("close")),
ohlcs: BiMap::new_json(1, price_path),
closes: BiMap::new_bin(1, &f("close")),
market_cap: BiMap::new_bin(1, &f("market_cap")),
price_1w_sma: BiMap::new_bin(1, &f("price_1w_sma")),
price_1w_sma_ratio: RatioDataset::import(datasets_path, "price_1w_sma")?,
@@ -139,7 +139,7 @@ impl PriceDatasets {
}
pub fn compute(&mut self, compute_data: &ComputeData, circulating_supply: &mut BiMap<f64>) {
let &ComputeData { dates, heights } = compute_data;
let &ComputeData { dates, heights, .. } = compute_data;
self.closes
.multi_insert_simple_transform(heights, dates, &mut self.ohlcs, &|ohlc| ohlc.close);
@@ -265,7 +265,7 @@ impl PriceDatasets {
|(last_value, date, closes)| {
let previous_value = date
.checked_sub_days(Days::new(4 * ONE_YEAR_IN_DAYS as u64))
.and_then(|date| closes.get_or_import(&WNaiveDate::wrap(date)))
.and_then(|date| closes.get_or_import(&Date::wrap(date)))
.unwrap_or_default();
(((last_value / previous_value).powf(1.0 / 4.0)) - 1.0) * 100.0
@@ -300,8 +300,8 @@ impl PriceDatasets {
.compute(compute_data, &mut self.closes, &mut self.price_200w_sma);
}
pub fn get_date_ohlc(&mut self, date: WNaiveDate) -> color_eyre::Result<OHLC> {
if self.ohlcs.date.is_date_safe(date) {
pub fn get_date_ohlc(&mut self, date: Date) -> color_eyre::Result<OHLC> {
if self.ohlcs.date.is_key_safe(date) {
Ok(self.ohlcs.date.get(&date).unwrap().to_owned())
} else {
let ohlc = self.get_from_daily_kraken(&date)?;
@@ -312,7 +312,7 @@ impl PriceDatasets {
}
}
fn get_from_daily_kraken(&mut self, date: &WNaiveDate) -> color_eyre::Result<OHLC> {
fn get_from_daily_kraken(&mut self, date: &Date) -> color_eyre::Result<OHLC> {
if self.kraken_daily.is_none() {
self.kraken_daily.replace(
Kraken::fetch_daily_prices()
@@ -330,7 +330,7 @@ impl PriceDatasets {
pub fn get_height_ohlc(
&mut self,
height: usize,
height: Height,
timestamp: u32,
previous_timestamp: Option<u32>,
) -> color_eyre::Result<OHLC> {
@@ -351,7 +351,7 @@ impl PriceDatasets {
let timestamp = clean_timestamp(timestamp);
if previous_timestamp.is_none() && height > 0 {
if previous_timestamp.is_none() && !height.is_first() {
panic!("Shouldn't be possible");
}
@@ -364,7 +364,7 @@ impl PriceDatasets {
.unwrap_or_else(|_| {
self.get_from_har_binance(timestamp, previous_timestamp)
.unwrap_or_else(|_| {
let date = WNaiveDate::from_timestamp(timestamp);
let date = Date::from_timestamp(timestamp);
panic!(
"Can't find the price for: height: {height} - date: {date}

View File

@@ -79,7 +79,7 @@ impl CapitalizationDataset {
closes: &mut BiMap<f32>,
cohort_supply: &mut BiMap<f64>,
) {
let &ComputeData { heights, dates } = compute_data;
let &ComputeData { heights, dates, .. } = compute_data;
self.realized_price.multi_insert_divide(
heights,

View File

@@ -5,7 +5,7 @@ mod input;
mod price_paid;
mod ratio;
mod realized;
// mod recap;
mod recap;
mod supply;
mod unrealized;
mod utxo;
@@ -15,7 +15,7 @@ pub use input::*;
pub use price_paid::*;
pub use ratio::*;
pub use realized::*;
// pub use recap::*;
pub use recap::*;
pub use supply::*;
pub use unrealized::*;
pub use utxo::*;

View File

@@ -4,7 +4,7 @@ use itertools::Itertools;
use crate::{
datasets::{AnyDataset, InsertData, MinInitialStates},
states::PricePaidState,
structs::{AnyBiMap, BiMap, WNaiveDate},
structs::{AnyBiMap, BiMap, Date, Height},
};
#[derive(Default, Allocative)]
@@ -217,13 +217,13 @@ impl PricePaidSubDataset {
}
}
fn insert_height_default(&mut self, height: usize) {
fn insert_height_default(&mut self, height: Height) {
self.inserted_as_mut_vec().into_iter().for_each(|bi| {
bi.height.insert_default(height);
})
}
fn insert_date_default(&mut self, date: WNaiveDate) {
fn insert_date_default(&mut self, date: Date) {
self.inserted_as_mut_vec().into_iter().for_each(|bi| {
bi.date.insert_default(date);
})

View File

@@ -68,7 +68,7 @@ impl RatioDataset {
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
&ComputeData { heights, dates, .. }: &ComputeData,
market_price: &mut BiMap<f32>,
other_price: &mut BiMap<f32>,
) {
@@ -112,9 +112,13 @@ impl RatioDataset {
self.ratio_1y_sma_momentum_oscillator
.height
.multi_insert_complex_transform(heights, &mut self.ratio.height, |(ratio, height)| {
(ratio / self.ratio_1y_sma.height.get_or_import(height)) - 1.0
});
.multi_insert_complex_transform(
heights,
&mut self.ratio.height,
|(ratio, height, ..)| {
(ratio / self.ratio_1y_sma.height.get_or_import(height).unwrap()) - 1.0
},
);
self.ratio_1y_sma_momentum_oscillator
.date

View File

@@ -130,7 +130,7 @@ impl RealizedSubDataset {
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
&ComputeData { heights, dates, .. }: &ComputeData,
market_cap: &mut BiMap<f32>,
) {
self.negative_realized_loss.multi_insert_simple_transform(

View File

@@ -6,33 +6,40 @@ use crate::{
DateMap, HeightMap,
};
#[derive(Default, Allocative)]
#[derive(Allocative)]
pub enum RecapTime {
Insert,
Compute,
}
#[derive(Allocative)]
pub struct RecapDataset<T> {
min_initial_states: MinInitialStates,
time: RecapTime,
// Computed
min: Option<DateMap<T>>,
max: Option<DateMap<T>>,
median: Option<DateMap<T>>,
average: Option<DateMap<T>>,
sum: Option<DateMap<T>>,
max: Option<DateMap<T>>,
_90p: Option<DateMap<T>>,
_75p: Option<DateMap<T>>,
median: Option<DateMap<T>>,
_25p: Option<DateMap<T>>,
_10p: Option<DateMap<T>>,
min: Option<DateMap<T>>,
}
#[derive(Default)]
struct RecapOptions {
min: bool,
max: bool,
median: bool,
pub struct RecapOptions {
average: bool,
sum: bool,
max: bool,
_90p: bool,
_75p: bool,
median: bool,
_25p: bool,
_10p: bool,
min: bool,
}
impl RecapOptions {
@@ -77,11 +84,16 @@ impl<T> RecapDataset<T>
where
T: MapValue,
{
pub fn import(parent_path: &str, options: RecapOptions) -> color_eyre::Result<Self> {
pub fn import(
parent_path: &str,
time: RecapTime,
options: RecapOptions,
) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
let mut s = Self {
min_initial_states: MinInitialStates::default(),
time,
min: options.min.then(|| DateMap::new_bin(1, &f("min"))),
max: options.max.then(|| DateMap::new_bin(1, &f("max"))),
@@ -102,44 +114,48 @@ where
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
&ComputeData { heights, dates, .. }: &ComputeData,
source: &mut HeightMap<f32>,
) {
if let Some(min) = self.min.as_ref() {
// v.push(min);
}
dates.iter().enumerate().for_each(|(index, date)| {
// let heights = heights_by_date.get(index).unwrap();
if let Some(max) = self.max.as_ref() {
// v.push(max);
}
if let Some(sum) = self.sum.as_ref() {
// v.push(sum);
}
if let Some(median) = self.median.as_ref() {
// v.push(median);
}
if let Some(average) = self.average.as_ref() {
// v.push(average);
}
if let Some(average) = self.average.as_ref() {
// v.push(average);
}
if let Some(max) = self.max.as_ref() {
// v.push(max);
}
if let Some(sum) = self.sum.as_ref() {
// v.push(sum);
}
if let Some(_90p) = self._90p.as_ref() {
// v.push(_90p);
}
if let Some(_90p) = self._90p.as_ref() {
// v.push(_90p);
}
if let Some(_75p) = self._75p.as_ref() {
// v.push(_75p);
}
if let Some(_75p) = self._75p.as_ref() {
// v.push(_75p);
}
if let Some(median) = self.median.as_ref() {
// v.push(median);
}
if let Some(_25p) = self._25p.as_ref() {
// v.push(_25p);
}
if let Some(_25p) = self._25p.as_ref() {
// v.push(_25p);
}
if let Some(_10p) = self._10p.as_ref() {
// v.push(_10p);
}
if let Some(_10p) = self._10p.as_ref() {
// v.push(_10p);
}
if let Some(min) = self.min.as_ref() {
// v.push(min);
}
});
}
}

View File

@@ -70,7 +70,7 @@ impl SupplySubDataset {
#[allow(unused_variables)]
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
&ComputeData { heights, dates, .. }: &ComputeData,
circulating_supply: &mut BiMap<f64>,
) {
self.supply_to_circulating_supply_ratio

View File

@@ -115,7 +115,7 @@ impl UnrealizedSubDataset {
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
&ComputeData { heights, dates, .. }: &ComputeData,
own_supply: &mut BiMap<f64>,
circulating_supply: &mut BiMap<f64>,
market_cap: &mut BiMap<f32>,

View File

@@ -107,7 +107,7 @@ impl TransactionDataset {
pub fn compute(
&mut self,
&ComputeData { heights, dates }: &ComputeData,
&ComputeData { heights, dates, .. }: &ComputeData,
circulating_supply: &mut BiMap<f64>,
block_interval: &mut HeightMap<u32>,
) {

View File

@@ -6,7 +6,7 @@ use crate::{
AnyDataset, AnyDatasetGroup, ComputeData, InsertData, MinInitialStates, SubDataset,
},
states::UTXOCohortId,
structs::{AnyBiMap, AnyDateMap, AnyHeightMap, BiMap, WNaiveDate},
structs::{AnyBiMap, AnyDateMap, AnyHeightMap, BiMap, Date, Height},
};
#[derive(Default, Allocative)]
@@ -122,31 +122,31 @@ impl UTXODataset {
// }
}
pub fn needs_insert_utxo(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_utxo(&self, height: Height, date: Date) -> bool {
self.subs.utxo.needs_insert(height, date)
}
pub fn needs_insert_capitalization(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_capitalization(&self, height: Height, date: Date) -> bool {
self.subs.capitalization.needs_insert(height, date)
}
pub fn needs_insert_supply(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_supply(&self, height: Height, date: Date) -> bool {
self.subs.supply.needs_insert(height, date)
}
pub fn needs_insert_price_paid(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_price_paid(&self, height: Height, date: Date) -> bool {
self.subs.price_paid.needs_insert(height, date)
}
pub fn needs_insert_realized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_realized(&self, height: Height, date: Date) -> bool {
self.subs.realized.needs_insert(height, date)
}
pub fn needs_insert_unrealized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_unrealized(&self, height: Height, date: Date) -> bool {
self.subs.unrealized.needs_insert(height, date)
}
pub fn needs_insert_input(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_input(&self, height: Height, date: Date) -> bool {
self.subs.input.needs_insert(height, date)
}

View File

@@ -9,7 +9,7 @@ use itertools::Itertools;
use crate::{
datasets::AnyDatasets,
states::{SplitByUTXOCohort, UTXOCohortId},
structs::{BiMap, WNaiveDate},
structs::{BiMap, Date, Height},
};
use super::{AnyDataset, ComputeData, InsertData, MinInitialStates};
@@ -55,7 +55,7 @@ impl UTXODatasets {
.for_each(|(cohort, _)| cohort.insert(insert_data))
}
pub fn needs_durable_states(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_durable_states(&self, height: Height, date: Date) -> bool {
let needs_insert_utxo = self.needs_insert_utxo(height, date);
let needs_insert_capitalization = self.needs_insert_capitalization(height, date);
let needs_insert_supply = self.needs_insert_supply(height, date);
@@ -67,51 +67,51 @@ impl UTXODatasets {
|| needs_one_shot_states
}
pub fn needs_one_shot_states(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_one_shot_states(&self, height: Height, date: Date) -> bool {
self.needs_insert_price_paid(height, date) || self.needs_insert_unrealized(height, date)
}
pub fn needs_sent_states(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_sent_states(&self, height: Height, date: Date) -> bool {
self.needs_insert_input(height, date) || self.needs_insert_realized(height, date)
}
pub fn needs_insert_utxo(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_utxo(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_utxo(height, date))
}
pub fn needs_insert_capitalization(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_capitalization(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_capitalization(height, date))
}
pub fn needs_insert_supply(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_supply(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_supply(height, date))
}
pub fn needs_insert_price_paid(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_price_paid(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_price_paid(height, date))
}
pub fn needs_insert_realized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_realized(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_realized(height, date))
}
pub fn needs_insert_unrealized(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_unrealized(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_unrealized(height, date))
}
pub fn needs_insert_input(&self, height: usize, date: WNaiveDate) -> bool {
pub fn needs_insert_input(&self, height: Height, date: Date) -> bool {
self.as_vec()
.iter()
.any(|(dataset, _)| dataset.needs_insert_input(height, date))