From 7d2c7ece6959c1c6e14413cb0f61042b0a767b17 Mon Sep 17 00:00:00 2001 From: FunctionsAPI Date: Tue, 19 Aug 2025 15:03:06 +0000 Subject: [PATCH] Automatic push from FunctionsAPI --- .DS_Store | Bin 0 -> 6148 bytes Cargo.lock | 3740 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 13 + README.md | 73 +- example_input.json | 20 + src/main.rs | 127 ++ 6 files changed, 3972 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 example_input.json create mode 100644 src/main.rs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Result { + let app = Application::new_from_compile_env(input.org_id, &input.project_id).unwrap(); + + for ((previous_id, newer_id), pipeline_id) in input + .older_ili_id + .into_iter() + .zip(input.newer_ili_id) + .zip(input.pipeline_id) + { + app.segment_growth_rate( + pipeline_id, + previous_id, + newer_id, + SegmentGrowthRateConfiguration::from(&input.criteria), + ) + .await + .map_err(|err| { + tracing::error!( + %pipeline_id, %newer_id, %previous_id, ?err, + "Error running comparison algorithm" + ); + format!("{err:?}") + })?; + } + + Ok(Output { + status: "Success".to_owned(), + }) +} + +#[derive(Debug, serde::Serialize)] +struct Output { + status: String, +} + +#[derive(Debug, serde::Deserialize)] +struct Input { + org_id: Uuid, + project_id: String, + pipeline_id: Vec, + older_ili_id: Vec, + newer_ili_id: Vec, + + #[serde(flatten)] + criteria: Configuration, +} + +#[derive(Debug, serde::Deserialize)] +pub struct Configuration { + /// The initial segment length in meters + #[serde(deserialize_with = "as_u64")] + initial_segment_length: u64, + /// The growth rate type + growth_rate_type: GRType, + /// The width of the depth histogram bins + #[serde(with = "serialize_percent")] + depth_histogram_width: Ratio, + /// The width of the length histogram bins + #[serde(with = "serialize_meter")] + length_histogram_width: Length, + /// The desired confidence level of the calculation + confidence: Confidence, + /// The minimum segment size in meters - this is the point at which the algorithm will no + /// longer split segments in two. + #[serde(deserialize_with = "as_u64")] + minimum_segment_length: u64, + /// The maximum segments size in meters for the purpose of validating segments + /// + /// Default value 1600 m. + #[serde(deserialize_with = "as_u64")] + maximum_segment_length: u64, +} + +#[derive(Debug, Clone, Copy, serde::Deserialize)] +#[serde(rename_all = "snake_case")] +enum GRType { + Mean, + Maximum, +} + +impl From for GrowthRateType { + fn from(value: GRType) -> GrowthRateType { + match value { + GRType::Mean => Self::MeanGrowthRate, + GRType::Maximum => Self::MaximumReported, + } + } +} + +#[derive(Debug, Clone, Copy, serde::Deserialize)] +#[serde(rename_all = "snake_case")] +enum Confidence { + High, + Low, +} + +impl From for ConfidenceLevel { + fn from(value: Confidence) -> Self { + match value { + Confidence::High => Self::High, + Confidence::Low => Self::Low, + } + } +} + +impl From<&Configuration> for SegmentGrowthRateConfiguration { + fn from(value: &Configuration) -> Self { + SegmentGrowthRateConfiguration::default() + .with_initial_segment_length(value.initial_segment_length as _) + .with_growth_rate_type(value.growth_rate_type.into()) + .with_depth_histogram_width(value.depth_histogram_width) + .with_length_histogram_width(value.length_histogram_width) + .with_confidence(value.confidence.into()) + .with_minimum_segment_length(value.minimum_segment_length as _) + .with_maximum_segment_length(value.maximum_segment_length as _) + } +}