parser: cohort ratio name changes

This commit is contained in:
k
2024-07-13 00:40:47 +02:00
parent 66bca200b4
commit fbbb0920c5
11 changed files with 90 additions and 46 deletions

View File

@@ -27,22 +27,14 @@ pub struct CohortDataset {
impl CohortDataset {
pub fn import(parent_path: &str, id: AddressCohortId) -> color_eyre::Result<Self> {
let name = id.as_name();
let name = id.as_name().map(|s| s.to_owned());
let split = id.as_split();
let folder_path = {
if let Some(name) = name {
format!("{parent_path}/{name}")
} else {
parent_path.to_owned()
}
};
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{s}/{name}")
if let Some(name) = &name {
Some(format!("{s}/{name}"))
} else {
format!("{parent_path}/{s}")
Some(s.to_owned())
}
};
@@ -51,11 +43,11 @@ impl CohortDataset {
split,
metadata: MetadataDataset::import(&folder_path)?,
all: SubDataset::import(&folder_path)?,
illiquid: SubDataset::import(&f("illiquid"))?,
liquid: SubDataset::import(&f("liquid"))?,
highly_liquid: SubDataset::import(&f("highly_liquid"))?,
metadata: MetadataDataset::import(parent_path, &name)?,
all: SubDataset::import(parent_path, &name)?,
illiquid: SubDataset::import(parent_path, &f("illiquid"))?,
liquid: SubDataset::import(parent_path, &f("liquid"))?,
highly_liquid: SubDataset::import(parent_path, &f("highly_liquid"))?,
};
s.min_initial_states

View File

@@ -18,8 +18,14 @@ pub struct MetadataDataset {
}
impl MetadataDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -23,8 +23,14 @@ pub struct CapitalizationDataset {
}
impl CapitalizationDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),
@@ -32,7 +38,13 @@ impl CapitalizationDataset {
realized_cap: BiMap::new_bin(1, &f("realized_cap")),
realized_cap_1m_net_change: BiMap::new_bin(1, &f("realized_cap_1m_net_change")),
realized_price: BiMap::new_bin(1, &f("realized_price")),
realized_price_ratio: RatioDataset::import(parent_path, "realized_price")?,
realized_price_ratio: RatioDataset::import(
parent_path,
&format!(
"{}realized_price",
name.as_ref().map_or("".to_owned(), |n| format!("{n}-"))
),
)?,
};
s.min_initial_states

View File

@@ -18,8 +18,14 @@ pub struct InputSubDataset {
}
impl InputSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -37,16 +37,16 @@ pub struct SubDataset {
}
impl SubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let s = Self {
capitalization: CapitalizationDataset::import(parent_path)?,
input: InputSubDataset::import(parent_path)?,
capitalization: CapitalizationDataset::import(parent_path, name)?,
input: InputSubDataset::import(parent_path, name)?,
// output: OutputSubDataset::import(parent_path)?,
price_paid: PricePaidSubDataset::import(parent_path)?,
realized: RealizedSubDataset::import(parent_path)?,
supply: SupplySubDataset::import(parent_path)?,
unrealized: UnrealizedSubDataset::import(parent_path)?,
utxo: UTXOSubDataset::import(parent_path)?,
price_paid: PricePaidSubDataset::import(parent_path, name)?,
realized: RealizedSubDataset::import(parent_path, name)?,
supply: SupplySubDataset::import(parent_path, name)?,
unrealized: UnrealizedSubDataset::import(parent_path, name)?,
utxo: UTXOSubDataset::import(parent_path, name)?,
};
Ok(s)

View File

@@ -34,8 +34,14 @@ pub struct PricePaidSubDataset {
}
impl PricePaidSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -29,8 +29,14 @@ pub struct RealizedSubDataset {
}
impl RealizedSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -20,8 +20,14 @@ pub struct SupplySubDataset {
}
impl SupplySubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -27,8 +27,14 @@ pub struct UnrealizedSubDataset {
}
impl UnrealizedSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -15,8 +15,14 @@ pub struct UTXOSubDataset {
}
impl UTXOSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}");
pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self {
min_initial_states: MinInitialStates::default(),

View File

@@ -20,14 +20,12 @@ pub struct UTXODataset {
impl UTXODataset {
pub fn import(parent_path: &str, id: UTXOCohortId) -> color_eyre::Result<Self> {
let name = id.name();
let folder_path = format!("{parent_path}/{name}");
let name = id.name().to_owned();
let mut s = Self {
min_initial_states: MinInitialStates::default(),
id,
subs: SubDataset::import(&folder_path)?,
subs: SubDataset::import(parent_path, &Some(name))?,
};
s.min_initial_states