Automatic push from FunctionsAPI
This commit is contained in:
parent
c0f49646d9
commit
5346309991
3422
Cargo.lock
generated
Normal file
3422
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-12741/adnoc-ingestion" }
|
||||
pipeline-application = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "FTHM-12741/adnoc-ingestion" }
|
||||
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,2 +1,55 @@
|
||||
# aabf823cde214401bc199b9be9a92f8d
|
||||
# Long term corrosion rate.
|
||||
|
||||
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)
|
||||
```
|
||||
|
||||
11
example_input.json
Normal file
11
example_input.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"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
Normal file
66
src/main.rs
Normal file
@ -0,0 +1,66 @@
|
||||
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