72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
use pipeline_application::application::{Application, Env, SegmentationConfiguration};
|
|
use pipeline_configuration::facilities::FacilityType;
|
|
use serde::Deserialize;
|
|
use uuid::Uuid;
|
|
|
|
// There is an issue with the data form component at the moment and its giving back
|
|
// a null value
|
|
const DEFAULT_PROJECT_ID: &str = "680b61b0aedd6f9e639d8699";
|
|
|
|
#[fathom_function::function]
|
|
async fn segment(input: Input) -> Result<String, String> {
|
|
let app = Application::new(
|
|
Env::Dev,
|
|
input.org_id,
|
|
input.project_id.as_deref().unwrap_or(DEFAULT_PROJECT_ID),
|
|
)
|
|
.unwrap();
|
|
|
|
for pipeline_id in input.pipeline_id {
|
|
app.segment(pipeline_id, &input.configuration)
|
|
.await
|
|
.map_err(|err| err.to_string())?;
|
|
}
|
|
|
|
Ok("Success".to_string())
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Input {
|
|
org_id: Uuid,
|
|
project_id: Option<String>,
|
|
pipeline_id: Vec<Uuid>,
|
|
#[serde(flatten)]
|
|
configuration: Configuration,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Configuration {
|
|
facilities: Vec<FacilityType>,
|
|
local_data: Vec<String>,
|
|
}
|
|
|
|
impl From<&Configuration> for SegmentationConfiguration {
|
|
fn from(value: &Configuration) -> Self {
|
|
let mut config = Self::default_false();
|
|
for fac in &value.facilities {
|
|
config = match fac {
|
|
FacilityType::InsulationJoint => config.by_insulation_joints(true),
|
|
FacilityType::Repair => config.by_repairs(true),
|
|
FacilityType::Valve => config.by_valves(true),
|
|
_ => config,
|
|
};
|
|
}
|
|
// TODO: add crossing configuration
|
|
for loc in &value.local_data {
|
|
config = match loc.as_str() {
|
|
"material_grade" => config.by_material_grade(true),
|
|
"coating_type" => config.by_coating_type(true),
|
|
"design_factor" => config.by_design_factor(true),
|
|
"high_consequence_area" => config.by_high_consequence_area(true),
|
|
"unusual_sensitive_area" => config.by_unusual_sensitive_area(true),
|
|
"joint_type" => config.by_joint_type(true),
|
|
"soil_type" => config.by_soil_type(true),
|
|
"soil_ph" => config.by_soil_ph(true),
|
|
_ => config,
|
|
}
|
|
}
|
|
|
|
config
|
|
}
|
|
}
|