Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6725c30ff |
3424
Cargo.lock
generated
Normal file
3424
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" }
|
||||||
58
README.md
58
README.md
@ -1,2 +1,58 @@
|
|||||||
# 53d9fcc59ac94c57a00310aacfa00122
|
# Corrosion coupon report upload
|
||||||
|
|
||||||
|
Approximately every 90 days during the entire lifetime of an active pipeline the corrosion
|
||||||
|
coupon in a corrosion coupon retrieval point should be replaced. The removed coupon should
|
||||||
|
be weighed to assess the metal loss of the coupon during the days it was exposed in the
|
||||||
|
pipeline.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
- `coupon_retrieval_point_id`: an `array` of `strings` which should be valid UUIDs for coupon
|
||||||
|
retrieval points on the pipeline
|
||||||
|
- `installation_date`: a `string` formatted as an ISO date representing the date the corrosion
|
||||||
|
coupon was installed in the pipeline.
|
||||||
|
- `retrieval_date`: a `string` formatted as an ISO date representing the date the corrosion
|
||||||
|
coupon was retrieved from the pipeline.
|
||||||
|
- `metal_loss`: a `float` representing the measured metal loss of the coupon.
|
||||||
|
- `inspector`: a `string` representing the identifier of the inspector
|
||||||
|
- `remarks`: a `string` for any additional remarks about the inspection
|
||||||
|
|
||||||
|
## 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/corrosion_coupon_report \
|
||||||
|
-d "Creates new corrosion coupon reports" \
|
||||||
|
-i org_id=string \
|
||||||
|
-i project_id=string \
|
||||||
|
-i pipeline_id=array \
|
||||||
|
-i coupon_retrieval_point_id=array \
|
||||||
|
-i installation_date=string \
|
||||||
|
-i retrieval_date=string \
|
||||||
|
-i metal_loss=float \
|
||||||
|
-i inspector=string \
|
||||||
|
-i remarks=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
|
||||||
|
jq '. | tojson' functions/corrosion_coupon_report/example_input.json | curl -d '@-' localhost:8080
|
||||||
|
```
|
||||||
|
|||||||
15
example_input.json
Normal file
15
example_input.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"coupon_retrieval_point_id": [
|
||||||
|
"01966d47-2d7e-75f0-bc6c-0ae8f5138bf8"
|
||||||
|
],
|
||||||
|
"inspector": "jbell",
|
||||||
|
"installation_date": "Fri May 18 2018",
|
||||||
|
"metal_loss": 0.005,
|
||||||
|
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||||
|
"pipeline_id": [
|
||||||
|
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||||
|
],
|
||||||
|
"project_id": "680b61b0aedd6f9e639d8699",
|
||||||
|
"remarks": null,
|
||||||
|
"retrieval_date": "Sun Aug 12 2018"
|
||||||
|
}
|
||||||
74
src/main.rs
Normal file
74
src/main.rs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
use fathom_function::{chrono::NaiveDate, forms::deserialize_date, tracing};
|
||||||
|
use pipeline_application::{
|
||||||
|
application::{Application, CorrosionCouponInitialReport},
|
||||||
|
serialization::serialize_gram,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uom::si::f64::Mass;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[fathom_function::function]
|
||||||
|
async fn upload_corrosion_coupon_report(input: Input) -> Result<Output, String> {
|
||||||
|
let app = Application::new_from_compile_env(input.org_id, input.project_id).unwrap();
|
||||||
|
|
||||||
|
for (pipeline_id, coupon_retrieval_point_id) in input
|
||||||
|
.pipeline_id
|
||||||
|
.into_iter()
|
||||||
|
.zip(input.coupon_retrieval_point_id)
|
||||||
|
{
|
||||||
|
app.upload_corrosion_coupon_report(pipeline_id, coupon_retrieval_point_id, &input.report)
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
tracing::error!(%pipeline_id, ?err, "Error uploading corrosion coupon report locations");
|
||||||
|
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>,
|
||||||
|
coupon_retrieval_point_id: Vec<Uuid>,
|
||||||
|
#[serde(flatten)]
|
||||||
|
report: Report,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct Report {
|
||||||
|
/// The date this corrosion coupon was installed in the pipeline.
|
||||||
|
#[serde(deserialize_with = "deserialize_date")]
|
||||||
|
installation_date: NaiveDate,
|
||||||
|
/// The date this corrosion coupon was removed from the pipeline.
|
||||||
|
#[serde(deserialize_with = "deserialize_date")]
|
||||||
|
retrieval_date: NaiveDate,
|
||||||
|
/// The metal loss of the coupon during the days exposed in the pipeline
|
||||||
|
#[serde(with = "serialize_gram")]
|
||||||
|
metal_loss: Mass,
|
||||||
|
/// The inspector name or identifier
|
||||||
|
inspector: String,
|
||||||
|
/// And additional remarks about the inspection
|
||||||
|
remarks: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Report> for CorrosionCouponInitialReport {
|
||||||
|
fn from(value: &Report) -> Self {
|
||||||
|
Self {
|
||||||
|
installation_date: value.installation_date,
|
||||||
|
retrieval_date: value.retrieval_date,
|
||||||
|
metal_loss: value.metal_loss,
|
||||||
|
inspector: value.inspector.to_owned(),
|
||||||
|
remarks: value.remarks.to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user