Compare commits
No commits in common. "v1" and "main" have entirely different histories.
3424
Cargo.lock
generated
3424
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@ -1,12 +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"] }
|
||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||
uom = { version = "0.36" }
|
||||
uuid = { version = "1" }
|
||||
55
README.md
55
README.md
@ -1,55 +1,2 @@
|
||||
# Long term corrosion rate.
|
||||
# 01e0a1d1912b4fada1824f2ac6a04943
|
||||
|
||||
This is calculated using a chosen ILI report and the growth rate is calculated on the
|
||||
assumption that the growth rate has been constant since the creation of the pipeline.
|
||||
|
||||
At it's most fundamental the calculation is simply `p / t` where `p` is the property (either
|
||||
the depth or length of the anomaly) and `t` is the time gap between the creation of the
|
||||
pipeline and the ILI report date.
|
||||
|
||||
## 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
|
||||
- `ili_id`: an `array` of `strings` which should be valid UUIDs for ili sequences
|
||||
- `aggregation`: an `string` each value should be one of the following
|
||||
- `segment`
|
||||
- `pipeline`
|
||||
- `girth_weld`
|
||||
- `every_1_km`
|
||||
- `every_5_km`
|
||||
- `every_10_km`
|
||||
|
||||
## 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_long_term_corrosion_growth_rate \
|
||||
-d "Run the long term corrosion growth rate calculation on using the provided ILI" \
|
||||
-i org_id=string \
|
||||
-i project_id=string \
|
||||
-i pipeline_id=array \
|
||||
-i ili_id=array \
|
||||
-i aggregation_method=object
|
||||
```
|
||||
|
||||
## 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_long_term_corrosion_growth_rate/example_input.json)
|
||||
```
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
{
|
||||
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||
"pipeline_id": [
|
||||
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||
],
|
||||
"ili_id": [
|
||||
"d0dd7c6b-6c54-4149-b46c-5e5b033fe6dd"
|
||||
],
|
||||
"project_id": "680b61b0aedd6f9e639d8699",
|
||||
"aggregation_method": "segment"
|
||||
}
|
||||
66
src/main.rs
66
src/main.rs
@ -1,66 +0,0 @@
|
||||
use fathom_function::tracing;
|
||||
use pipeline_application::application::{self, Application};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uom::si::f64::Length;
|
||||
use uom::si::length::kilometer;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[fathom_function::function]
|
||||
async fn long_term_corrosion_growth_rate(input: Input) -> Result<Output, String> {
|
||||
let app = Application::new_from_compile_env(input.org_id, input.project_id).unwrap();
|
||||
let aggregation = input.aggregation_method;
|
||||
|
||||
for (pipeline_id, ili_id) in input.pipeline_id.into_iter().zip(input.ili_id) {
|
||||
app.long_term_corrosion_growth_rate(pipeline_id, ili_id, aggregation)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!(
|
||||
%pipeline_id, %ili_id, ?err,
|
||||
"Error running long term corrosion growth rate calculation"
|
||||
);
|
||||
format!("{err:?}")
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(Output {
|
||||
status: "Success".to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Output {
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Input {
|
||||
org_id: Uuid,
|
||||
project_id: String,
|
||||
pipeline_id: Vec<Uuid>,
|
||||
ili_id: Vec<Uuid>,
|
||||
aggregation_method: Aggregation,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
enum Aggregation {
|
||||
Segment,
|
||||
Pipeline,
|
||||
GirthWeld,
|
||||
Every1Km,
|
||||
Every5Km,
|
||||
Every10Km,
|
||||
}
|
||||
|
||||
impl From<Aggregation> for application::Aggregation {
|
||||
fn from(value: Aggregation) -> Self {
|
||||
match value {
|
||||
Aggregation::Segment => Self::Segment,
|
||||
Aggregation::Pipeline => Self::Pipeline,
|
||||
Aggregation::GirthWeld => Self::GirthWeld,
|
||||
Aggregation::Every1Km => Self::Distance(Length::new::<kilometer>(1.0)),
|
||||
Aggregation::Every5Km => Self::Distance(Length::new::<kilometer>(5.0)),
|
||||
Aggregation::Every10Km => Self::Distance(Length::new::<kilometer>(10.0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user