-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): add transform_offset method to geometry types and updat…
…e example workflow (#661)
- Loading branch information
Showing
29 changed files
with
571 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
engine/runtime/action-processor/src/feature/type_filter.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use std::collections::HashMap; | ||
|
||
use once_cell::sync::Lazy; | ||
use reearth_flow_runtime::{ | ||
channels::ProcessorChannelForwarder, | ||
errors::BoxedError, | ||
event::EventHub, | ||
executor_operation::{ExecutorContext, NodeContext}, | ||
node::{Port, Processor, ProcessorFactory, DEFAULT_PORT}, | ||
}; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
use super::errors::FeatureProcessorError; | ||
|
||
pub static UNFILTERED_PORT: Lazy<Port> = Lazy::new(|| Port::new("unfiltered")); | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct FeatureTypeFilterFactory; | ||
|
||
impl ProcessorFactory for FeatureTypeFilterFactory { | ||
fn name(&self) -> &str { | ||
"FeatureTypeFilter" | ||
} | ||
|
||
fn description(&self) -> &str { | ||
"Filters features by feature type" | ||
} | ||
|
||
fn parameter_schema(&self) -> Option<schemars::schema::RootSchema> { | ||
Some(schemars::schema_for!(FeatureTypeFilter)) | ||
} | ||
|
||
fn categories(&self) -> &[&'static str] { | ||
&["Feature"] | ||
} | ||
|
||
fn get_input_ports(&self) -> Vec<Port> { | ||
vec![DEFAULT_PORT.clone()] | ||
} | ||
|
||
fn get_output_ports(&self) -> Vec<Port> { | ||
vec![DEFAULT_PORT.clone(), UNFILTERED_PORT.clone()] | ||
} | ||
|
||
fn build( | ||
&self, | ||
_ctx: NodeContext, | ||
_event_hub: EventHub, | ||
_action: String, | ||
with: Option<HashMap<String, Value>>, | ||
) -> Result<Box<dyn Processor>, BoxedError> { | ||
let process: FeatureTypeFilter = if let Some(with) = with { | ||
let value: Value = serde_json::to_value(with).map_err(|e| { | ||
FeatureProcessorError::TransformerFactory(format!( | ||
"Failed to serialize `with` parameter: {}", | ||
e | ||
)) | ||
})?; | ||
serde_json::from_value(value).map_err(|e| { | ||
FeatureProcessorError::TransformerFactory(format!( | ||
"Failed to deserialize `with` parameter: {}", | ||
e | ||
)) | ||
})? | ||
} else { | ||
return Err(FeatureProcessorError::TransformerFactory( | ||
"Missing required parameter `with`".to_string(), | ||
) | ||
.into()); | ||
}; | ||
Ok(Box::new(process)) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct FeatureTypeFilter { | ||
target_types: Vec<String>, | ||
} | ||
|
||
impl Processor for FeatureTypeFilter { | ||
fn process( | ||
&mut self, | ||
ctx: ExecutorContext, | ||
fw: &mut dyn ProcessorChannelForwarder, | ||
) -> Result<(), BoxedError> { | ||
let feature = &ctx.feature; | ||
let Some(feature_type) = feature.feature_type() else { | ||
fw.send(ctx.new_with_feature_and_port(feature.clone(), UNFILTERED_PORT.clone())); | ||
return Ok(()); | ||
}; | ||
if self.target_types.contains(&feature_type) { | ||
fw.send(ctx.new_with_feature_and_port(feature.clone(), DEFAULT_PORT.clone())); | ||
} else { | ||
fw.send(ctx.new_with_feature_and_port(feature.clone(), UNFILTERED_PORT.clone())); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn finish( | ||
&self, | ||
_ctx: NodeContext, | ||
_fw: &mut dyn ProcessorChannelForwarder, | ||
) -> Result<(), BoxedError> { | ||
Ok(()) | ||
} | ||
|
||
fn name(&self) -> &str { | ||
"FeatureTypeFilter" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.