Automatic push from FunctionsAPI
This commit is contained in:
parent
abbabb0288
commit
f7a19d48ab
3738
Cargo.lock
generated
Normal file
3738
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "web"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
fathom-function = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "main" }
|
||||
pipeline-application = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "main" }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||
uuid = { version = "1" }
|
||||
58
README.md
58
README.md
@ -1,2 +1,58 @@
|
||||
# 3e291e5044e546edb30363a51a97a830
|
||||
# Runs the ILI clustering algorithm for all the clustering rules
|
||||
|
||||
Clustering criteria for pipeline defects refer to the guidelines or criteria that are used to
|
||||
determine whether a group of defects in a pipeline should be considered a "cluster." These
|
||||
criteria are typically based on a combination of factors, including the size, location, and
|
||||
severity of the defects, as well as the spacing between them. See [clustering function readme](../ili_clustering/README.md) for more info.
|
||||
|
||||
This function runs the clustering algorithm for all the rules for a given ILI report.
|
||||
|
||||
## Input
|
||||
|
||||
### Arguments
|
||||
|
||||
- `org_id`: as string which should be a valid `uuid` for the organization
|
||||
- `project_id`: the id of the data project where the pipeline data is found
|
||||
- `pipeline_id`: an `array` of `strings` which should be valid UUIDs for pipelines
|
||||
- `size_settings`: a string representing the size setting for clustering, possible values
|
||||
- `original`
|
||||
- `tolerance`
|
||||
- `interaction`: a string representing the interaction setting for clustering, possible values
|
||||
- `enabled`
|
||||
- `disabled`
|
||||
- `surface_location`: a string representing the surface location setting for clustering, possible values
|
||||
- `matching`
|
||||
- `any`
|
||||
|
||||
## Creating the function on the platform
|
||||
|
||||
To create this function on the platform using the `cli` set up the port forwarding as shown in README.
|
||||
|
||||
Then run the following command to create the function.
|
||||
|
||||
```bash
|
||||
cargo run functions create \
|
||||
-f functions/ili_clustering_all \
|
||||
-d "Runs the ILI clustering algorithm" \
|
||||
-i org_id=string \
|
||||
-i project_id=string \
|
||||
-i pipeline_id=array \
|
||||
-i ili_id=array \
|
||||
-i size_settings=string \
|
||||
-i interaction=string \
|
||||
-i surface_location=string
|
||||
```
|
||||
|
||||
## Testing the function locally
|
||||
|
||||
You can run and test the function locally by running
|
||||
|
||||
```bash
|
||||
cargo run
|
||||
```
|
||||
|
||||
Then you can check it work with `curl` as follows
|
||||
|
||||
```bash
|
||||
curl localhost:8080 -d $(jq '. | tojson' functions/ili_clustering_all/example_input.json)
|
||||
```
|
||||
|
||||
13
example_input.json
Normal file
13
example_input.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"ili_id": [
|
||||
"d0dd7c6b-6c54-4149-b46c-5e5b033fe6dd"
|
||||
],
|
||||
"interaction": "disabled",
|
||||
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||
"pipeline_id": [
|
||||
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||
],
|
||||
"project_id": "680b61b0aedd6f9e639d8699",
|
||||
"size_settings": "original",
|
||||
"surface_location": "matching"
|
||||
}
|
||||
104
src/main.rs
Normal file
104
src/main.rs
Normal file
@ -0,0 +1,104 @@
|
||||
use fathom_function::tracing;
|
||||
use pipeline_application::application::{
|
||||
AnomalySizeSetting, Application, ClusteringConfig, Interaction as ClusteringInteraction,
|
||||
SurfaceLocationSensitivity,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[fathom_function::function]
|
||||
async fn ili_clustering_all(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_all_rules(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 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,
|
||||
}
|
||||
|
||||
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::default()
|
||||
.with_interaction(value.interaction.into())
|
||||
.with_surface_location(value.surface_location.into())
|
||||
.with_size_settings(value.size_settings.into())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user