Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7564318c02 |
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 = "FTHM-13063/sgr" }
|
||||
pipeline-application = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "FTHM-13063/sgr" }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||
uom = { version = "0.36" }
|
||||
uuid = { version = "1" }
|
||||
73
README.md
73
README.md
@ -1,2 +1,73 @@
|
||||
# 4d4c9e5515394fdab729a0f97ca0fdfd
|
||||
# Segment growth rate
|
||||
|
||||
The segment growth rate calculation is useful when the ILI comparison is unable to get good
|
||||
results.
|
||||
|
||||
Before performing any comparison or analysis between two ILI reports, the user must verify the
|
||||
following parameters are consistent across both inspections:
|
||||
|
||||
- *Detection Threshold*: Ensure the detection threshold is the same in both ILI reports.
|
||||
- *Reporting Threshold*: Ensure the reporting threshold is the same in both ILI reports.
|
||||
- *Tool Tolerances*: Ensure the specified tool tolerances are the same in both ILI reports.
|
||||
|
||||
Failure to verify these parameters may result in inaccurate comparison or false growth
|
||||
assessments.
|
||||
|
||||
## 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
|
||||
- `older_ili_id`: a `array` of string values representing a valid `uuid` for an ili report sequence
|
||||
- `newer_ili_id`: a `array` of string values representing a valid `uuid` for an ili report sequence
|
||||
- `initial_segment_length`: a `float` value
|
||||
- `depth_histogram_width`: a `float` value
|
||||
- `length_histogram_width`: a `float` value
|
||||
- `maximum_segment_length`: a `float` value
|
||||
- `minimum_segment_length`: a `float` value
|
||||
- `growth_rate_type`: a `string` whose values should be one of
|
||||
- `mean`
|
||||
- `maximum`
|
||||
- `confidence`: a `string` whose value should be one of
|
||||
- `high`
|
||||
- `low`
|
||||
|
||||
## 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/acr_segment_growth_rate \
|
||||
-d "Run the segment growth rate calculation" \
|
||||
-i org_id=string \
|
||||
-i project_id=string \
|
||||
-i pipeline_id=array \
|
||||
-i older_ili_id=array \
|
||||
-i newer_ili_id=array \
|
||||
-i initial_segment_length=integer \
|
||||
-i growth_rate_type=string \
|
||||
-i depth_histogram_width=float \
|
||||
-i length_histogram_width=float \
|
||||
-i confidence=float \
|
||||
-i maximum_segment_length=float \
|
||||
-i minimum_segment_length=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/acr_segment_growth_rate/example_input.json)
|
||||
```
|
||||
|
||||
21
example_input.json
Normal file
21
example_input.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"feature_location_threshold": "5",
|
||||
"minimum_depth_growth_threshold": "0",
|
||||
"minimum_length_growth_threshold": "-2",
|
||||
"newer_ili_id": [
|
||||
"d0dd7c6b-6c54-4149-b46c-5e5b033fe6dd"
|
||||
],
|
||||
"older_ili_id": [
|
||||
"514167e0-f197-4edb-a382-f8db9b048613"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
123
src/main.rs
Normal file
123
src/main.rs
Normal file
@ -0,0 +1,123 @@
|
||||
use fathom_function::tracing;
|
||||
use pipeline_application::{
|
||||
application::{Application, ConfidenceLevel, GrowthRateType, SegmentGrowthRateConfiguration},
|
||||
serialization::{serialize_meter, serialize_percent},
|
||||
};
|
||||
use uom::si::f64::{Length, Ratio};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[fathom_function::function]
|
||||
async fn segment_growth_rate(input: Input) -> Result<Output, String> {
|
||||
let app = Application::new_from_compile_env(input.org_id, &input.project_id).unwrap();
|
||||
|
||||
for ((previous_id, newer_id), pipeline_id) in input
|
||||
.older_ili_id
|
||||
.into_iter()
|
||||
.zip(input.newer_ili_id)
|
||||
.zip(input.pipeline_id)
|
||||
{
|
||||
app.segment_growth_rate(
|
||||
pipeline_id,
|
||||
previous_id,
|
||||
newer_id,
|
||||
SegmentGrowthRateConfiguration::from(&input.criteria),
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!(
|
||||
%pipeline_id, %newer_id, %previous_id, ?err,
|
||||
"Error running comparison algorithm"
|
||||
);
|
||||
format!("{err:?}")
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(Output {
|
||||
status: "Success".to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct Output {
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Input {
|
||||
org_id: Uuid,
|
||||
project_id: String,
|
||||
pipeline_id: Vec<Uuid>,
|
||||
older_ili_id: Vec<Uuid>,
|
||||
newer_ili_id: Vec<Uuid>,
|
||||
|
||||
#[serde(flatten)]
|
||||
criteria: Configuration,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct Configuration {
|
||||
/// The initial segment length in meters
|
||||
initial_segment_length: u32,
|
||||
/// The growth rate type
|
||||
growth_rate_type: GRType,
|
||||
/// The width of the depth histogram bins
|
||||
#[serde(with = "serialize_percent")]
|
||||
depth_histogram_width: Ratio,
|
||||
/// The width of the length histogram bins
|
||||
#[serde(with = "serialize_meter")]
|
||||
length_histogram_width: Length,
|
||||
/// The desired confidence level of the calculation
|
||||
confidence: Confidence,
|
||||
/// The minimum segment size in meters - this is the point at which the algorithm will no
|
||||
/// longer split segments in two.
|
||||
minimum_segment_length: u32,
|
||||
/// The maximum segments size in meters for the purpose of validating segments
|
||||
///
|
||||
/// Default value 1600 m.
|
||||
max_segment_size: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum GRType {
|
||||
Mean,
|
||||
Maximum,
|
||||
}
|
||||
|
||||
impl From<GRType> for GrowthRateType {
|
||||
fn from(value: GRType) -> GrowthRateType {
|
||||
match value {
|
||||
GRType::Mean => Self::MeanGrowthRate,
|
||||
GRType::Maximum => Self::MaximumReported,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum Confidence {
|
||||
High,
|
||||
Low,
|
||||
}
|
||||
|
||||
impl From<Confidence> for ConfidenceLevel {
|
||||
fn from(value: Confidence) -> Self {
|
||||
match value {
|
||||
Confidence::High => Self::High,
|
||||
Confidence::Low => Self::Low,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Configuration> for SegmentGrowthRateConfiguration {
|
||||
fn from(value: &Configuration) -> Self {
|
||||
SegmentGrowthRateConfiguration::default()
|
||||
.with_initial_segment_length(value.initial_segment_length)
|
||||
.with_growth_rate_type(value.growth_rate_type.into())
|
||||
.with_depth_histogram_width(value.depth_histogram_width)
|
||||
.with_length_histogram_width(value.length_histogram_width)
|
||||
.with_confidence(value.confidence.into())
|
||||
.with_minimum_segment_length(value.minimum_segment_length)
|
||||
.with_maximum_segment_length(value.max_segment_size)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user