add flows
This commit is contained in:
parent
94459d5481
commit
7b6d58be33
4 changed files with 290 additions and 26 deletions
|
@ -196,25 +196,29 @@ impl Variant {
|
|||
}
|
||||
|
||||
pub async fn get_unique_origins(&self) -> Vec<String> {
|
||||
Transaction::unique(
|
||||
doc! {
|
||||
"item": &self.item,
|
||||
"variant": &self.variant
|
||||
},
|
||||
"origin",
|
||||
unique_flows(
|
||||
&Transaction::unique(
|
||||
doc! {
|
||||
"item": &self.item,
|
||||
"variant": &self.variant
|
||||
},
|
||||
"origin",
|
||||
)
|
||||
.await,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_unique_destinations(&self) -> Vec<String> {
|
||||
Transaction::unique(
|
||||
doc! {
|
||||
"item": &self.item,
|
||||
"variant": &self.variant
|
||||
},
|
||||
"consumed.destination",
|
||||
unique_flows(
|
||||
&Transaction::unique(
|
||||
doc! {
|
||||
"item": &self.item,
|
||||
"variant": &self.variant
|
||||
},
|
||||
"consumed.destination",
|
||||
)
|
||||
.await,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn price_history_by_origin(&self, origin: &str) -> Vec<Price> {
|
||||
|
@ -287,3 +291,29 @@ impl Variant {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unique_flows(i: &[String]) -> Vec<String> {
|
||||
let mut unique_vec: Vec<String> = Vec::new();
|
||||
|
||||
for s in i {
|
||||
// Check if the string starts with "flow::"
|
||||
if let Some(suffix) = s.strip_prefix("flow::") {
|
||||
// Extract the part after "flow::" and split on "::" to get the kind (ignoring id)
|
||||
let parts: Vec<&str> = suffix.split("::").collect();
|
||||
if let Some(kind) = parts.get(0) {
|
||||
// Build the common prefix "flow::kind"
|
||||
let common_prefix = format!("flow::{}", kind);
|
||||
|
||||
if !unique_vec.contains(&common_prefix) {
|
||||
unique_vec.push(common_prefix);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If the string doesn't start with "flow::", retain it
|
||||
// Assumption: Except "flow::" values, everything should be already unique
|
||||
unique_vec.push(s.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
unique_vec
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue