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
+9 -17
View File
@@ -27,22 +27,14 @@ pub struct CohortDataset {
impl CohortDataset { impl CohortDataset {
pub fn import(parent_path: &str, id: AddressCohortId) -> color_eyre::Result<Self> { 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 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| { let f = |s: &str| {
if let Some(name) = name { if let Some(name) = &name {
format!("{parent_path}/{s}/{name}") Some(format!("{s}/{name}"))
} else { } else {
format!("{parent_path}/{s}") Some(s.to_owned())
} }
}; };
@@ -51,11 +43,11 @@ impl CohortDataset {
split, split,
metadata: MetadataDataset::import(&folder_path)?, metadata: MetadataDataset::import(parent_path, &name)?,
all: SubDataset::import(&folder_path)?, all: SubDataset::import(parent_path, &name)?,
illiquid: SubDataset::import(&f("illiquid"))?, illiquid: SubDataset::import(parent_path, &f("illiquid"))?,
liquid: SubDataset::import(&f("liquid"))?, liquid: SubDataset::import(parent_path, &f("liquid"))?,
highly_liquid: SubDataset::import(&f("highly_liquid"))?, highly_liquid: SubDataset::import(parent_path, &f("highly_liquid"))?,
}; };
s.min_initial_states s.min_initial_states
@@ -18,8 +18,14 @@ pub struct MetadataDataset {
} }
impl MetadataDataset { impl MetadataDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+15 -3
View File
@@ -23,8 +23,14 @@ pub struct CapitalizationDataset {
} }
impl CapitalizationDataset { impl CapitalizationDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
@@ -32,7 +38,13 @@ impl CapitalizationDataset {
realized_cap: BiMap::new_bin(1, &f("realized_cap")), 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_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: 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 s.min_initial_states
+8 -2
View File
@@ -18,8 +18,14 @@ pub struct InputSubDataset {
} }
impl InputSubDataset { impl InputSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+8 -8
View File
@@ -37,16 +37,16 @@ pub struct SubDataset {
} }
impl 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 { let s = Self {
capitalization: CapitalizationDataset::import(parent_path)?, capitalization: CapitalizationDataset::import(parent_path, name)?,
input: InputSubDataset::import(parent_path)?, input: InputSubDataset::import(parent_path, name)?,
// output: OutputSubDataset::import(parent_path)?, // output: OutputSubDataset::import(parent_path)?,
price_paid: PricePaidSubDataset::import(parent_path)?, price_paid: PricePaidSubDataset::import(parent_path, name)?,
realized: RealizedSubDataset::import(parent_path)?, realized: RealizedSubDataset::import(parent_path, name)?,
supply: SupplySubDataset::import(parent_path)?, supply: SupplySubDataset::import(parent_path, name)?,
unrealized: UnrealizedSubDataset::import(parent_path)?, unrealized: UnrealizedSubDataset::import(parent_path, name)?,
utxo: UTXOSubDataset::import(parent_path)?, utxo: UTXOSubDataset::import(parent_path, name)?,
}; };
Ok(s) Ok(s)
+8 -2
View File
@@ -34,8 +34,14 @@ pub struct PricePaidSubDataset {
} }
impl PricePaidSubDataset { impl PricePaidSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+8 -2
View File
@@ -29,8 +29,14 @@ pub struct RealizedSubDataset {
} }
impl RealizedSubDataset { impl RealizedSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+8 -2
View File
@@ -20,8 +20,14 @@ pub struct SupplySubDataset {
} }
impl SupplySubDataset { impl SupplySubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+8 -2
View File
@@ -27,8 +27,14 @@ pub struct UnrealizedSubDataset {
} }
impl UnrealizedSubDataset { impl UnrealizedSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+8 -2
View File
@@ -15,8 +15,14 @@ pub struct UTXOSubDataset {
} }
impl UTXOSubDataset { impl UTXOSubDataset {
pub fn import(parent_path: &str) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, name: &Option<String>) -> color_eyre::Result<Self> {
let f = |s: &str| format!("{parent_path}/{s}"); let f = |s: &str| {
if let Some(name) = name {
format!("{parent_path}/{name}/{s}")
} else {
format!("{parent_path}/{s}")
}
};
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
+2 -4
View File
@@ -20,14 +20,12 @@ pub struct UTXODataset {
impl UTXODataset { impl UTXODataset {
pub fn import(parent_path: &str, id: UTXOCohortId) -> color_eyre::Result<Self> { pub fn import(parent_path: &str, id: UTXOCohortId) -> color_eyre::Result<Self> {
let name = id.name(); let name = id.name().to_owned();
let folder_path = format!("{parent_path}/{name}");
let mut s = Self { let mut s = Self {
min_initial_states: MinInitialStates::default(), min_initial_states: MinInitialStates::default(),
id, id,
subs: SubDataset::import(&folder_path)?, subs: SubDataset::import(parent_path, &Some(name))?,
}; };
s.min_initial_states s.min_initial_states