Automatic push from FunctionsAPI
This commit is contained in:
parent
e8fe1d99e3
commit
641d92e1c3
3738
Cargo.lock
generated
Normal file
3738
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[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"] }
|
||||||
|
uuid = { version = "1" }
|
||||||
43
README.md
43
README.md
@ -1,2 +1,43 @@
|
|||||||
# 913d5c67641a49f0b29715ae7fcc51ef
|
# Linear regression growth prediction
|
||||||
|
|
||||||
|
The objective of this calculation is to derive the expected length and depth of anomalies at a
|
||||||
|
particular date in the future (the target_date) for each matched anomaly 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 each be a valid uuid representing a pipeline.
|
||||||
|
- `target_date`: a `string` representing the date for which the corrosion growth rate should be predicted.
|
||||||
|
|
||||||
|
## 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_linear_regression \
|
||||||
|
-d "Run the linear regression prediction calculation" \
|
||||||
|
-i org_id=string \
|
||||||
|
-i project_id=string \
|
||||||
|
-i target_date=string \
|
||||||
|
-i pipeline_id=array
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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_linear_regression/example_input.json)
|
||||||
|
```
|
||||||
|
|||||||
8
example_input.json
Normal file
8
example_input.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"target_date": "2023-10-24",
|
||||||
|
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||||
|
"pipeline_id": [
|
||||||
|
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||||
|
],
|
||||||
|
"project_id": "680b61b0aedd6f9e639d8699"
|
||||||
|
}
|
||||||
33
src/main.rs
Normal file
33
src/main.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use fathom_function::{chrono::NaiveDate, tracing};
|
||||||
|
use pipeline_application::application::Application;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[fathom_function::function]
|
||||||
|
async fn linear_regression_growth_prediction(input: Input) -> Result<Output, String> {
|
||||||
|
let app = Application::new_from_compile_env(input.org_id, &input.project_id).unwrap();
|
||||||
|
for pipeline_id in input.pipeline_id {
|
||||||
|
app.linear_regression_growth_prediction(pipeline_id, input.target_date)
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
tracing::error!(%pipeline_id, ?err, "Error running linear regression 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,
|
||||||
|
target_date: Option<NaiveDate>,
|
||||||
|
pipeline_id: Vec<Uuid>,
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user