Automatic push from FunctionsAPI
This commit is contained in:
parent
a1c8ca4584
commit
bb274cc9db
3624
Cargo.lock
generated
Normal file
3624
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[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"] }
|
||||
uom = { version = "0.36" }
|
||||
uuid = { version = "1" }
|
||||
71
README.md
71
README.md
@ -1,2 +1,71 @@
|
||||
# de5e28613d5a409c907a1b57291c3f14
|
||||
# ILI comparison (compare all)
|
||||
|
||||
This function will run all possible ILI comparisons for a given pipeline.
|
||||
|
||||
See [ILI comparison](../ili_comparison/README.md) for more details of the comparison algorithm.
|
||||
|
||||
## 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`: a `array` of string values representing a valid `uuid` for a pipeline
|
||||
- `weld_location_threshold`: a `float` value
|
||||
- `feature_location_threshold`: a `float` value
|
||||
- `upstream_girth_threshold`: a `float` value
|
||||
- `orientation_threshold`: a `float` value
|
||||
- `minimum_depth_growth_threshold`: a `float` value
|
||||
- `minimum_length_growth_threshold`: a `float` value
|
||||
- `length_criteria_status`: a `string` whose values should be one of
|
||||
- `enabled`
|
||||
- `disabled`
|
||||
- `surface_location_criteria`: a `string` whose value should be one of
|
||||
- `matching`
|
||||
- `any`
|
||||
- `target_minimum_match_rate`: a `float` value
|
||||
|
||||
## 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_compare_all \
|
||||
-d "Runs the ILI comparison algorithm for all combinations of ILI reports for the given pipeline" \
|
||||
-o org_id=string \
|
||||
-o project_id=string \
|
||||
-o pipeline_ids=array \
|
||||
-o unique_pipeline_ids=array \
|
||||
-o matched_ids=array \
|
||||
-o unmatched_ids=array \
|
||||
-o summary_ids=array \
|
||||
-i org_id=string \
|
||||
-i project_id=string \
|
||||
-i pipeline_id=array \
|
||||
-i weld_location_threshold=float \
|
||||
-i upstream_girth_threshold=float \
|
||||
-i feature_location_threshold=float \
|
||||
-i orientation_threshold=float \
|
||||
-i minimum_depth_growth_threshold=float \
|
||||
-i minimum_length_growth_threshold=float \
|
||||
-i length_criteria_status=string \
|
||||
-i surface_location_criteria=string \
|
||||
-i target_minimum_match_rate=float
|
||||
```
|
||||
|
||||
## 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_compare_all/example_input.json)
|
||||
```
|
||||
|
||||
15
example_input.json
Normal file
15
example_input.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"feature_location_threshold": "5",
|
||||
"minimum_depth_growth_threshold": "0",
|
||||
"minimum_length_growth_threshold": "-2",
|
||||
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||
"orientation_threshold": "15",
|
||||
"pipeline_id": [
|
||||
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||
],
|
||||
"project_id": "680b61b0aedd6f9e639d8699",
|
||||
"surface_location_criteria": "matching",
|
||||
"target_minimum_match_rate": "25",
|
||||
"upstream_girth_threshold": "0.05",
|
||||
"weld_location_threshold": "9"
|
||||
}
|
||||
139
src/main.rs
Normal file
139
src/main.rs
Normal file
@ -0,0 +1,139 @@
|
||||
use fathom_function::tracing;
|
||||
use pipeline_application::{
|
||||
application::{
|
||||
Application, IliComparisonOutput, MatchingCriteria, SurfaceLocationCriteria as SLC,
|
||||
},
|
||||
serialization::{
|
||||
serialize_meter, serialize_millimeter, serialize_orientation_min, serialize_percent,
|
||||
},
|
||||
};
|
||||
use uom::si::f64::{Angle, Length, Ratio};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[fathom_function::function]
|
||||
async fn ili_compare_all(input: Input) -> Result<Output, String> {
|
||||
let mut output = Output::new(input.org_id, &input.project_id);
|
||||
let app = Application::new_from_compile_env(input.org_id, &input.project_id).unwrap();
|
||||
|
||||
for pipeline_id in input.pipeline_id {
|
||||
let result = app
|
||||
.ili_compare_all(pipeline_id, MatchingCriteria::from(&input.criteria))
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!(%pipeline_id, ?err, "Error running comparison algorithm");
|
||||
format!("{err:?}")
|
||||
})?;
|
||||
output.push_result(pipeline_id, result);
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, Default)]
|
||||
struct Output {
|
||||
// TODO: remove org_id, project_id, unique_pipeline_ids once function outputs from previous
|
||||
// nodes are all visible in downstream nodes (FTHM-11016).
|
||||
org_id: Uuid,
|
||||
unique_pipeline_ids: Vec<Uuid>,
|
||||
project_id: String,
|
||||
pipeline_ids: Vec<Uuid>,
|
||||
matched_ids: Vec<Uuid>,
|
||||
unmatched_ids: Vec<Uuid>,
|
||||
summary_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
impl Output {
|
||||
fn new(org_id: Uuid, project_id: impl ToString) -> Self {
|
||||
Self {
|
||||
org_id,
|
||||
project_id: project_id.to_string(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn push_result(&mut self, pipeline_id: Uuid, ili_comparison_result: Vec<IliComparisonOutput>) {
|
||||
self.unique_pipeline_ids.push(pipeline_id);
|
||||
ili_comparison_result.into_iter().for_each(|res| {
|
||||
self.pipeline_ids.push(pipeline_id);
|
||||
self.matched_ids.push(res.matched_id);
|
||||
self.unmatched_ids.push(res.unmatched_id);
|
||||
self.summary_ids.push(res.summary_id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Input {
|
||||
org_id: Uuid,
|
||||
project_id: String,
|
||||
pipeline_id: Vec<Uuid>,
|
||||
|
||||
#[serde(flatten)]
|
||||
criteria: Criteria,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Criteria {
|
||||
#[serde(with = "serialize_meter")]
|
||||
weld_location_threshold: Length,
|
||||
#[serde(with = "serialize_meter")]
|
||||
feature_location_threshold: Length,
|
||||
#[serde(with = "serialize_meter")]
|
||||
upstream_girth_threshold: Length,
|
||||
#[serde(with = "serialize_orientation_min")]
|
||||
orientation_threshold: Angle,
|
||||
#[serde(with = "serialize_percent")]
|
||||
minimum_depth_growth_threshold: Ratio,
|
||||
#[serde(with = "serialize_millimeter")]
|
||||
minimum_length_growth_threshold: Length,
|
||||
surface_location_criteria: SurfaceLocationCriteria,
|
||||
#[serde(with = "serialize_percent")]
|
||||
target_minimum_match_rate: Ratio,
|
||||
#[serde(default)]
|
||||
length_criteria_status: Status,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum SurfaceLocationCriteria {
|
||||
Matching,
|
||||
Any,
|
||||
}
|
||||
|
||||
impl From<SurfaceLocationCriteria> for SLC {
|
||||
fn from(value: SurfaceLocationCriteria) -> Self {
|
||||
match value {
|
||||
SurfaceLocationCriteria::Matching => Self::Matching,
|
||||
SurfaceLocationCriteria::Any => Self::Any,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, serde::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum Status {
|
||||
#[default]
|
||||
Enabled,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
impl Status {
|
||||
fn is_disabled(&self) -> bool {
|
||||
matches!(self, Self::Disabled)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Criteria> for MatchingCriteria {
|
||||
fn from(value: &Criteria) -> Self {
|
||||
MatchingCriteria::default()
|
||||
.with_weld_location_threshold(value.weld_location_threshold)
|
||||
.with_feature_location_threshold(value.feature_location_threshold)
|
||||
.with_upstream_girth_threshold(value.upstream_girth_threshold)
|
||||
.with_orientation_threshold(value.orientation_threshold)
|
||||
.with_minimum_depth_growth_threshold(value.minimum_depth_growth_threshold)
|
||||
.with_minimum_length_growth_threshold(value.minimum_length_growth_threshold)
|
||||
.with_surface_location_criteria(value.surface_location_criteria)
|
||||
.with_target_minimum_match_rate(value.target_minimum_match_rate)
|
||||
.with_disable_length_criteria(value.length_criteria_status.is_disabled())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user