Skip to content

Commit

Permalink
Modify ranked_outliers distance search condition & Release 0.15.0 (#86
Browse files Browse the repository at this point in the history
)

- Change the distance search criteria to support a single search.
- Change the type of id in the `Rankedoutlier` field from `StringNumber` to `ID`.
- Change the part about `RankedOutlierTotalCount` to count the total count differently.
- Bump version to 0.15.0

Closes: #83, #87, #88
  • Loading branch information
kimhanbeom authored and sehkone committed Nov 15, 2023
1 parent b2ac87b commit 148d73c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.15.0] - 2023-11-15

### Changed

- Change the type of `id` in `ranked_outlier`/`saved_outlier` queries to `StringNumber`.
- Modified Ranked Outliers graphql query to take in a SearchFilter with
`tag` and `remark`
- Change the distance search conditions for `ranked outliers`.
- Start only: Search for outliers with the same distance value
- Start/End: Search for outliers with distance values in the range.
- Change the data type of the `id` in the `RankedOutlier` structure from `StringNumber`
to `ID`.
- Change the part about `RankedOutlierTotalCount` to count the total count differently
depending on whether it is `saved_outliers` or `ranked_outliers`.

## [0.14.5] - 2023-11-02

Expand Down Expand Up @@ -328,7 +335,7 @@ across our system.

- An initial version.

[Unreleased]: https://github.com/aicers/review-web/compare/0.14.5...main
[0.15.0]: https://github.com/aicers/review-web/compare/0.14.5...0.15.0
[0.14.5]: https://github.com/aicers/review-web/compare/0.14.4...0.14.5
[0.14.4]: https://github.com/aicers/review-web/compare/0.14.3...0.14.4
[0.14.3]: https://github.com/aicers/review-web/compare/0.14.2...0.14.3
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "review-web"
version = "0.15.0-alpha.1"
version = "0.15.0"
edition = "2021"

[dependencies]
anyhow = "1"
async-graphql = { version = "6", features = ["chrono", "string_number"] }
async-graphql = { version = "6", features = ["chrono"] }
async-graphql-axum = "6"
async-trait = "0.1"
axum = { version = "0.6", features = ["headers", "macros"] }
Expand Down
32 changes: 24 additions & 8 deletions src/graphql/outlier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::graphql::{earliest_key, latest_key};
use anyhow::anyhow;
use async_graphql::{
connection::{query, Connection, Edge, EmptyFields},
types::{StringNumber, ID},
types::ID,
ComplexObject, Context, InputObject, Object, ObjectType, OutputType, Result, SimpleObject,
};
use bincode::Options;
Expand All @@ -22,6 +22,7 @@ use std::cmp;

pub const TIMESTAMP_SIZE: usize = 8;
const DEFAULT_OUTLIER_SIZE: usize = 50;
const DISTANCE_EPSILON: f64 = 0.1;

#[derive(Default)]
pub(super) struct OutlierMutation;
Expand Down Expand Up @@ -189,13 +190,16 @@ async fn load_outliers(
RankedOutlierTotalCount {
model_id,
timestamp,
check_saved: true,
},
)
}

#[derive(Debug, SimpleObject)]
#[graphql(complex)]
pub(super) struct RankedOutlier {
id: StringNumber<i64>,
#[graphql(skip)]
id: i64,
model_id: i32,
timestamp: i64,
rank: i64,
Expand All @@ -204,6 +208,13 @@ pub(super) struct RankedOutlier {
saved: bool,
}

#[ComplexObject]
impl RankedOutlier {
async fn id(&self) -> ID {
ID(self.id.to_string())
}
}

impl FromKeyValue for RankedOutlier {
fn from_key_value(key: &[u8], value: &[u8]) -> anyhow::Result<Self> {
let (model_id, timestamp, rank, id, source) =
Expand Down Expand Up @@ -247,6 +258,7 @@ impl From<PreserveOutliersInput> for RankedOutlierKey {
struct RankedOutlierTotalCount {
model_id: i32,
timestamp: Option<i64>,
check_saved: bool,
}

#[Object]
Expand All @@ -262,15 +274,18 @@ impl RankedOutlierTotalCount {
let store = crate::graphql::get_store(ctx).await?;
let map = store.outlier_map().into_prefix_map(&prefix);

let count = map
.iter_forward()?
.filter(|(_k, v)| {
let iter = map.iter_forward()?;
let count = if self.check_saved {
iter.filter(|(_k, v)| {
let (_, saved): RankedOutlierValue = bincode::DefaultOptions::new()
.deserialize(v)
.unwrap_or_default();
saved
})
.count();
.count()
} else {
iter.count()
};
Ok(count)
}
}
Expand Down Expand Up @@ -659,6 +674,7 @@ async fn load_ranked_outliers_with_filter(
RankedOutlierTotalCount {
model_id,
timestamp,
check_saved: false,
},
);
connection
Expand Down Expand Up @@ -798,7 +814,7 @@ where

if let Some(filter) = filter {
if filter.remark.is_some() || tag_id_list.is_some() {
let key = key(&node.source, Utc.timestamp_nanos(node.id.0));
let key = key(&node.source, Utc.timestamp_nanos(node.id));
if let Some(value) = remarks_map.get_by_key(&key)? {
let value: TriageResponse = bincode::DefaultOptions::new()
.deserialize(value.as_ref())
Expand Down Expand Up @@ -841,7 +857,7 @@ where
if node.distance < start || node.distance > end {
continue;
}
} else if node.distance < start {
} else if (node.distance - start).abs() > DISTANCE_EPSILON {
continue;
}
}
Expand Down

0 comments on commit 148d73c

Please sign in to comment.