142 lines
3.4 KiB
Rust
142 lines
3.4 KiB
Rust
use fathom_function::tracing;
|
|
use pipeline_application::application::{
|
|
AnomalySizeSetting, Application, ClusteringConfig, Interaction as ClusteringInteraction,
|
|
Rule as ClusteringRule, SurfaceLocationSensitivity,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
#[fathom_function::function]
|
|
async fn ili_clustering(input: Input) -> Result<Output, String> {
|
|
let app = Application::new_from_compile_env(input.org_id, input.project_id).unwrap();
|
|
|
|
for (pipeline_id, ili_id) in input.pipeline_id.into_iter().zip(input.ili_id) {
|
|
app.ili_clustering(pipeline_id, ili_id, &input.config)
|
|
.await
|
|
.map_err(|err| {
|
|
tracing::error!(%pipeline_id, %ili_id, ?err, "Error running clustering algorithm");
|
|
format!("{err:?}")
|
|
})?;
|
|
}
|
|
|
|
Ok(Output {
|
|
status: "Success".to_owned(),
|
|
})
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
struct Output {
|
|
status: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
enum Rule {
|
|
Rule1,
|
|
Rule2,
|
|
Rule3,
|
|
Rule4,
|
|
Rule5,
|
|
Rule6,
|
|
Rule7,
|
|
Rule8,
|
|
Rule9,
|
|
Rule10,
|
|
Rule11,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
enum SizeSettings {
|
|
Original,
|
|
Tolerance,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum Interaction {
|
|
Enabled,
|
|
Disabled,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum SurfaceLocation {
|
|
Matching,
|
|
Any,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Input {
|
|
org_id: Uuid,
|
|
project_id: String,
|
|
pipeline_id: Vec<Uuid>,
|
|
ili_id: Vec<Uuid>,
|
|
#[serde(flatten)]
|
|
config: Config,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Config {
|
|
size_settings: SizeSettings,
|
|
interaction: Interaction,
|
|
surface_location: SurfaceLocation,
|
|
rule: Rule,
|
|
}
|
|
|
|
impl From<Rule> for ClusteringRule {
|
|
fn from(value: Rule) -> Self {
|
|
match value {
|
|
Rule::Rule1 => Self::Rule1,
|
|
Rule::Rule2 => Self::Rule2,
|
|
Rule::Rule3 => Self::Rule3,
|
|
Rule::Rule4 => Self::Rule4,
|
|
Rule::Rule5 => Self::Rule5,
|
|
Rule::Rule6 => Self::Rule6,
|
|
Rule::Rule7 => Self::Rule7,
|
|
Rule::Rule8 => Self::Rule8,
|
|
Rule::Rule9 => Self::Rule9,
|
|
Rule::Rule10 => Self::Rule10,
|
|
Rule::Rule11 => Self::Rule11,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<SizeSettings> for AnomalySizeSetting {
|
|
fn from(value: SizeSettings) -> Self {
|
|
match value {
|
|
SizeSettings::Original => Self::Original,
|
|
SizeSettings::Tolerance => Self::WithTolerance,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<SurfaceLocation> for SurfaceLocationSensitivity {
|
|
fn from(value: SurfaceLocation) -> Self {
|
|
match value {
|
|
SurfaceLocation::Matching => Self::Matching,
|
|
SurfaceLocation::Any => Self::Any,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<Interaction> for ClusteringInteraction {
|
|
fn from(value: Interaction) -> Self {
|
|
match value {
|
|
Interaction::Enabled => Self::Enabled,
|
|
Interaction::Disabled => Self::Disabled,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<&Config> for ClusteringConfig {
|
|
fn from(value: &Config) -> Self {
|
|
Self {
|
|
interaction: value.interaction.into(),
|
|
surface_location: value.surface_location.into(),
|
|
size_settings: value.size_settings.into(),
|
|
rule: value.rule.into(),
|
|
}
|
|
}
|
|
}
|