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 { 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, ili_id: Vec, aggregation_method: Aggregation, } #[derive(Debug, Deserialize, Clone, Copy)] #[serde(rename_all = "snake_case")] enum Aggregation { Segment, Pipeline, GirthWeld, Every1Km, Every5Km, Every10Km, } impl From 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::(1.0)), Aggregation::Every5Km => Self::Distance(Length::new::(5.0)), Aggregation::Every10Km => Self::Distance(Length::new::(10.0)), } } }