Compare commits

..

No commits in common. "v5" and "main" have entirely different histories.
v5 ... main

6 changed files with 1 additions and 3972 deletions

BIN
.DS_Store vendored

Binary file not shown.

3740
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +0,0 @@
[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"] }
serde-this-or-that = "0.5.0"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
uom = { version = "0.36" }
uuid = { version = "1" }

View File

@ -1,73 +1,2 @@
# Segment growth rate # ca9ccc2880ca4d1890e07702dc8cb738
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=string \
-i maximum_segment_length=float \
-i minimum_segment_length=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/acr_segment_growth_rate/example_input.json)
```

View File

@ -1,20 +0,0 @@
{
"confidence": "high",
"depth_histogram_width": "4",
"growth_rate_type": "mean",
"initial_segment_length": 1600,
"length_histogram_width": "0.1",
"maximum_segment_length": "1600",
"minimum_segment_length": "100",
"newer_ili_id": [
"71e73c8c-7bb4-49c6-bb85-fa7eb1e21b0b"
],
"older_ili_id": [
"2a86cd06-a43a-4552-aa17-951bcf3fda2b"
],
"org_id": "b4d6cbfd-c444-4a0b-9fcd-39984c68e860",
"pipeline_id": [
"019759fb-52a6-7db3-86ed-ed4505af4837"
],
"project_id": "68482a0d64a45c363e1bea9e"
}

View File

@ -1,127 +0,0 @@
use fathom_function::tracing;
use pipeline_application::{
application::{Application, ConfidenceLevel, GrowthRateType, SegmentGrowthRateConfiguration},
serialization::{serialize_meter, serialize_percent},
};
use serde_this_or_that::as_u64;
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
#[serde(deserialize_with = "as_u64")]
initial_segment_length: u64,
/// 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.
#[serde(deserialize_with = "as_u64")]
minimum_segment_length: u64,
/// The maximum segments size in meters for the purpose of validating segments
///
/// Default value 1600 m.
#[serde(deserialize_with = "as_u64")]
maximum_segment_length: u64,
}
#[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 as _)
.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 as _)
.with_maximum_segment_length(value.maximum_segment_length as _)
}
}