Skip to content

Commit

Permalink
Add range check to ranked outliers
Browse files Browse the repository at this point in the history
  • Loading branch information
marioCluml committed Oct 27, 2023
1 parent 34cfd52 commit 22cc51a
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/graphql/outlier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,24 @@ impl OutlierMutation {
#[derive(Default)]
pub(super) struct OutlierQuery;

#[allow(clippy::module_name_repetitions)]
#[derive(InputObject, Serialize)]
pub struct OutlierTimeRange {
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
}

#[allow(clippy::module_name_repetitions)]
#[derive(InputObject, Serialize)]
pub struct OutlierDistanceRange {
start: Option<f64>,
end: Option<f64>,
}

#[derive(InputObject, Serialize)]
pub struct SearchFilterInput {
pub time: Option<OutlierTimeRange>,
distance: Option<f64>,
distance: Option<OutlierDistanceRange>,
}

#[Object]
Expand Down Expand Up @@ -602,6 +610,7 @@ fn latest_outlier_key(before: &str) -> Result<Vec<u8>> {
Ok(end)
}

#[allow(clippy::too_many_arguments, clippy::type_complexity)] // since this is called within `load` only
async fn load_ranked_outliers_with_filter(
ctx: &Context<'_>,
model_id: ID,
Expand Down Expand Up @@ -663,9 +672,9 @@ where

let (nodes, has_more) = if let Some(after) = after {
let to = earliest_key(&after)?;
iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_ge, &filter, last)
iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_ge, filter, last)
} else {
iter_through_search_filter_nodes(iter, &[], always_true, &filter, last)
iter_through_search_filter_nodes(iter, &[], always_true, filter, last)
}?;
Ok((nodes, has_more, false))
} else {
Expand All @@ -679,9 +688,9 @@ where

let (nodes, has_more) = if let Some(before) = before {
let to = latest_key(&before)?;
iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_le, &filter, first)
iter_through_search_filter_nodes(iter, &to, cmp::Ordering::is_le, filter, first)
} else {
iter_through_search_filter_nodes(iter, &[], always_true, &filter, first)
iter_through_search_filter_nodes(iter, &[], always_true, filter, first)
}?;
Ok((nodes, false, has_more))
}
Expand Down Expand Up @@ -720,23 +729,27 @@ where
{
continue;
}
} else {
if node.timestamp < start.timestamp_nanos_opt().unwrap_or_default() {
continue;
}
} else if node.timestamp < start.timestamp_nanos_opt().unwrap_or_default() {
continue;
}
} else {
if let Some(end) = end {
if node.timestamp > end.timestamp_nanos_opt().unwrap_or_default() {
continue;
}
} else if let Some(end) = end {
if node.timestamp > end.timestamp_nanos_opt().unwrap_or_default() {
continue;
}
}
}

if let Some(distance) = filter.distance {
if node.distance != distance {
continue;
if let Some(distance) = &filter.distance {
let start = distance.start;
let end = distance.end;
if let Some(start) = start {
if let Some(end) = end {
if node.distance < start || node.distance > end {
continue;
}
} else if (((node.distance * 10.0).round() / 10.0) - start).abs() > 0.0 {
continue;
}
}
}
}
Expand Down

0 comments on commit 22cc51a

Please sign in to comment.