pynode-flow 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pynode/__init__.py +37 -0
- pynode/__main__.py +9 -0
- pynode/_perf.py +65 -0
- pynode/_version.py +24 -0
- pynode/api/__init__.py +15 -0
- pynode/api/helpers.py +79 -0
- pynode/api/nodes.py +423 -0
- pynode/api/services.py +124 -0
- pynode/api/sse.py +58 -0
- pynode/api/uploads.py +59 -0
- pynode/api/workflows.py +466 -0
- pynode/config.py +93 -0
- pynode/install_nodes.py +143 -0
- pynode/main.py +118 -0
- pynode/node_registry.py +156 -0
- pynode/nodes/AutoSyncNode/auto_sync_node.py +151 -0
- pynode/nodes/BBoxMetricsNode/__init__.py +3 -0
- pynode/nodes/BBoxMetricsNode/bbox_metrics_node.py +250 -0
- pynode/nodes/BBoxMetricsNode/requirements.txt +1 -0
- pynode/nodes/BatchNode/__init__.py +3 -0
- pynode/nodes/BatchNode/batch_node.py +86 -0
- pynode/nodes/BatchNode/requirements.txt +1 -0
- pynode/nodes/CameraNode/__init__.py +4 -0
- pynode/nodes/CameraNode/camera_node.py +204 -0
- pynode/nodes/CameraNode/requirements.txt +2 -0
- pynode/nodes/ChangeNode/__init__.py +1 -0
- pynode/nodes/ChangeNode/change_node.py +255 -0
- pynode/nodes/ChangeNode/requirements.txt +1 -0
- pynode/nodes/ConfidenceFilterNode/__init__.py +4 -0
- pynode/nodes/ConfidenceFilterNode/confidence_filter_node.py +208 -0
- pynode/nodes/ConfidenceFilterNode/requirements.txt +1 -0
- pynode/nodes/CounterNode/__init__.py +3 -0
- pynode/nodes/CounterNode/counter_node.py +191 -0
- pynode/nodes/CropNode/__init__.py +4 -0
- pynode/nodes/CropNode/crop_node.py +317 -0
- pynode/nodes/CropNode/requirements.txt +2 -0
- pynode/nodes/DebugNode/__init__.py +4 -0
- pynode/nodes/DebugNode/debug_node.py +169 -0
- pynode/nodes/DebugNode/requirements.txt +1 -0
- pynode/nodes/DelayNode/delay_node.py +218 -0
- pynode/nodes/DelayNode/requirements.txt +1 -0
- pynode/nodes/DrawPredictionsNode/__init__.py +3 -0
- pynode/nodes/DrawPredictionsNode/draw_predictions_node.py +365 -0
- pynode/nodes/DrawPredictionsNode/requirements.txt +2 -0
- pynode/nodes/ErrorNode/error_node.py +94 -0
- pynode/nodes/ErrorNode/requirements.txt +1 -0
- pynode/nodes/FilterNode/__init__.py +3 -0
- pynode/nodes/FilterNode/filter_node.py +102 -0
- pynode/nodes/FilterNode/requirements.txt +1 -0
- pynode/nodes/FrameSourceNode/__init__.py +4 -0
- pynode/nodes/FrameSourceNode/frame_source_node.py +319 -0
- pynode/nodes/FrameSourceNode/requirements.txt +1 -0
- pynode/nodes/FunctionNode/__init__.py +3 -0
- pynode/nodes/FunctionNode/function_node.py +168 -0
- pynode/nodes/FunctionNode/requirements.txt +1 -0
- pynode/nodes/GateNode/gate_node.py +60 -0
- pynode/nodes/GateNode/requirements.txt +1 -0
- pynode/nodes/GetiUploadNode/__init__.py +3 -0
- pynode/nodes/GetiUploadNode/geti_upload_node.py +278 -0
- pynode/nodes/GetiUploadNode/requirements.txt +1 -0
- pynode/nodes/ImageFormatNode/__init__.py +4 -0
- pynode/nodes/ImageFormatNode/image_format_node.py +310 -0
- pynode/nodes/ImageFormatNode/requirements.txt +2 -0
- pynode/nodes/ImageUploadNode/image_upload_node.py +96 -0
- pynode/nodes/ImageViewerNode/__init__.py +4 -0
- pynode/nodes/ImageViewerNode/image_viewer_node.py +162 -0
- pynode/nodes/ImageViewerNode/requirements.txt +2 -0
- pynode/nodes/ImageWriterNode/__init__.py +3 -0
- pynode/nodes/ImageWriterNode/imagewriter_node.py +352 -0
- pynode/nodes/ImageWriterNode/requirements.txt +1 -0
- pynode/nodes/InferenceNode/InferenceEngine/__init__.py +15 -0
- pynode/nodes/InferenceNode/InferenceEngine/device_detection.py +149 -0
- pynode/nodes/InferenceNode/InferenceEngine/engines/base_engine.py +155 -0
- pynode/nodes/InferenceNode/InferenceEngine/engines/example_engine_template.py +272 -0
- pynode/nodes/InferenceNode/InferenceEngine/engines/geti_engine.py +309 -0
- pynode/nodes/InferenceNode/InferenceEngine/engines/onnx_engine.py +346 -0
- pynode/nodes/InferenceNode/InferenceEngine/engines/pass_engine.py +86 -0
- pynode/nodes/InferenceNode/InferenceEngine/engines/ultralytics_engine.py +863 -0
- pynode/nodes/InferenceNode/InferenceEngine/inference_engine_factory.py +533 -0
- pynode/nodes/InferenceNode/InferenceEngine/readme.md +107 -0
- pynode/nodes/InferenceNode/InferenceEngine/result_converters.py +121 -0
- pynode/nodes/InferenceNode/inference_node.py +451 -0
- pynode/nodes/InferenceNode/requirements.txt +13 -0
- pynode/nodes/InjectNode/inject_node.py +245 -0
- pynode/nodes/InjectNode/requirements.txt +1 -0
- pynode/nodes/JoinNode/__init__.py +3 -0
- pynode/nodes/JoinNode/join_node.py +156 -0
- pynode/nodes/JoinNode/requirements.txt +1 -0
- pynode/nodes/LabelFilterNode/__init__.py +3 -0
- pynode/nodes/LabelFilterNode/label_filter_node.py +188 -0
- pynode/nodes/LabelFilterNode/requirements.txt +1 -0
- pynode/nodes/MQTTNode/__init__.py +8 -0
- pynode/nodes/MQTTNode/mqtt_in_node.py +148 -0
- pynode/nodes/MQTTNode/mqtt_out_node.py +157 -0
- pynode/nodes/MQTTNode/mqtt_service.py +367 -0
- pynode/nodes/MQTTNode/requirements.txt +1 -0
- pynode/nodes/MessageWriterNode/__init__.py +7 -0
- pynode/nodes/MessageWriterNode/messagereader_node.py +568 -0
- pynode/nodes/MessageWriterNode/messagewriter_node.py +505 -0
- pynode/nodes/OmronCameraNode/__init__.py +3 -0
- pynode/nodes/OmronCameraNode/omron_camera_node.py +652 -0
- pynode/nodes/OmronCameraNode/requirements.txt +4 -0
- pynode/nodes/OpenCV/__init__.py +1 -0
- pynode/nodes/OpenCV/arithmetic_node.py +376 -0
- pynode/nodes/OpenCV/bitwise_node.py +127 -0
- pynode/nodes/OpenCV/blend_node.py +127 -0
- pynode/nodes/OpenCV/blob_detector_node.py +233 -0
- pynode/nodes/OpenCV/blur_node.py +141 -0
- pynode/nodes/OpenCV/color_space_node.py +139 -0
- pynode/nodes/OpenCV/colormap_node.py +262 -0
- pynode/nodes/OpenCV/contours_node.py +258 -0
- pynode/nodes/OpenCV/denormalize_coords_node.py +365 -0
- pynode/nodes/OpenCV/draw_node.py +312 -0
- pynode/nodes/OpenCV/edge_detector_node.py +177 -0
- pynode/nodes/OpenCV/equirectangular_node.py +447 -0
- pynode/nodes/OpenCV/fft_node.py +102 -0
- pynode/nodes/OpenCV/focus_estimation_node.py +189 -0
- pynode/nodes/OpenCV/frequency_filter_node.py +241 -0
- pynode/nodes/OpenCV/histogram_node.py +160 -0
- pynode/nodes/OpenCV/hough_circles_node.py +224 -0
- pynode/nodes/OpenCV/hough_lines_node.py +243 -0
- pynode/nodes/OpenCV/in_range_node.py +186 -0
- pynode/nodes/OpenCV/morphology_node.py +136 -0
- pynode/nodes/OpenCV/normalize_coords_node.py +344 -0
- pynode/nodes/OpenCV/paste_node.py +244 -0
- pynode/nodes/OpenCV/perspective_node.py +174 -0
- pynode/nodes/OpenCV/realsense_depth_node.py +253 -0
- pynode/nodes/OpenCV/requirements.txt +2 -0
- pynode/nodes/OpenCV/resize_node.py +175 -0
- pynode/nodes/OpenCV/rotate_node.py +159 -0
- pynode/nodes/OpenCV/template_match_node.py +227 -0
- pynode/nodes/OpenCV/threshold_node.py +167 -0
- pynode/nodes/PointInShapeNode/__init__.py +3 -0
- pynode/nodes/PointInShapeNode/point_in_shape_node.py +313 -0
- pynode/nodes/PointInShapeNode/requirements.txt +2 -0
- pynode/nodes/PolygonMetricsNode/__init__.py +3 -0
- pynode/nodes/PolygonMetricsNode/polygon_metrics_node.py +331 -0
- pynode/nodes/PolygonMetricsNode/requirements.txt +2 -0
- pynode/nodes/QueueLengthProbeNode/__init__.py +3 -0
- pynode/nodes/QueueLengthProbeNode/queue_length_probe_node.py +116 -0
- pynode/nodes/Qwen3VLMNode/__init__.py +3 -0
- pynode/nodes/Qwen3VLMNode/qwen3_vlm_node.py +519 -0
- pynode/nodes/Qwen3VLMNode/requirements.txt +5 -0
- pynode/nodes/RESTEndpointNode/__init__.py +3 -0
- pynode/nodes/RESTEndpointNode/rest_endpoint_node.py +491 -0
- pynode/nodes/RangeNode/__init__.py +3 -0
- pynode/nodes/RangeNode/range_node.py +115 -0
- pynode/nodes/RangeNode/requirements.txt +1 -0
- pynode/nodes/RateProbeNode/__init__.py +3 -0
- pynode/nodes/RateProbeNode/rate_probe_node.py +183 -0
- pynode/nodes/RateProbeNode/requirements.txt +1 -0
- pynode/nodes/RoboflowUploadNode/__init__.py +3 -0
- pynode/nodes/RoboflowUploadNode/requirements.txt +1 -0
- pynode/nodes/RoboflowUploadNode/roboflow_upload_node.py +229 -0
- pynode/nodes/SliceNode/README.md +149 -0
- pynode/nodes/SliceNode/__init__.py +5 -0
- pynode/nodes/SliceNode/merge_predictions_node.py +444 -0
- pynode/nodes/SliceNode/requirements.txt +3 -0
- pynode/nodes/SliceNode/slice_collector_node.py +370 -0
- pynode/nodes/SliceNode/slice_image_node.py +380 -0
- pynode/nodes/SplitNode/__init__.py +3 -0
- pynode/nodes/SplitNode/requirements.txt +1 -0
- pynode/nodes/SplitNode/split_node.py +155 -0
- pynode/nodes/SwitchNode/requirements.txt +1 -0
- pynode/nodes/SwitchNode/switch_node.py +259 -0
- pynode/nodes/SyncNode/__init__.py +3 -0
- pynode/nodes/SyncNode/sync_node.py +287 -0
- pynode/nodes/TemplateNode/requirements.txt +1 -0
- pynode/nodes/TemplateNode/template_node.py +86 -0
- pynode/nodes/TrackerNode/__init__.py +2 -0
- pynode/nodes/TrackerNode/supervision_tracker_node.py +248 -0
- pynode/nodes/TrackerNode/tracker_node.py +745 -0
- pynode/nodes/UltralyticsNode/__init__.py +4 -0
- pynode/nodes/UltralyticsNode/requirements.txt +2 -0
- pynode/nodes/UltralyticsNode/ultralytics_node.py +364 -0
- pynode/nodes/UnknownNode/__init__.py +93 -0
- pynode/nodes/VLLMNode/__init__.py +3 -0
- pynode/nodes/VLLMNode/vllm_node.py +345 -0
- pynode/nodes/VideoReaderNode/__init__.py +3 -0
- pynode/nodes/VideoReaderNode/video_reader_node.py +425 -0
- pynode/nodes/VideoWriterNode/__init__.py +3 -0
- pynode/nodes/VideoWriterNode/video_writer_node.py +441 -0
- pynode/nodes/WebhookNode/__init__.py +3 -0
- pynode/nodes/WebhookNode/webhook_node.py +591 -0
- pynode/nodes/__init__.py +109 -0
- pynode/nodes/base_node.py +562 -0
- pynode/nodes/image_utils.py +291 -0
- pynode/nodes/info.py +109 -0
- pynode/nodes/mDNSNode/__init__.py +13 -0
- pynode/nodes/mDNSNode/mdns_broadcast_node.py +214 -0
- pynode/nodes/mDNSNode/mdns_discovery_node.py +362 -0
- pynode/nodes/mDNSNode/mdns_manager.py +399 -0
- pynode/nodes/mDNSNode/requirements.txt +1 -0
- pynode/nodes/messages.py +81 -0
- pynode/server.py +187 -0
- pynode/static/images/favicon4.png +0 -0
- pynode/static/index.html +200 -0
- pynode/static/js/README.md +139 -0
- pynode/static/js/auth.js +89 -0
- pynode/static/js/clipboard.js +152 -0
- pynode/static/js/config.js +14 -0
- pynode/static/js/connections.js +844 -0
- pynode/static/js/debug.js +524 -0
- pynode/static/js/events.js +775 -0
- pynode/static/js/history.js +199 -0
- pynode/static/js/main.js +55 -0
- pynode/static/js/minimap.js +242 -0
- pynode/static/js/nodes.js +995 -0
- pynode/static/js/palette.js +255 -0
- pynode/static/js/properties.js +1270 -0
- pynode/static/js/selection.js +241 -0
- pynode/static/js/state.js +211 -0
- pynode/static/js/ui-utils.js +28 -0
- pynode/static/js/viewport.js +204 -0
- pynode/static/js/workflow.js +469 -0
- pynode/static/js/workflows.js +344 -0
- pynode/static/style.css +2751 -0
- pynode/workflow_engine.py +483 -0
- pynode/workflow_manager.py +440 -0
- pynode_flow-0.2.0.dist-info/METADATA +520 -0
- pynode_flow-0.2.0.dist-info/RECORD +227 -0
- pynode_flow-0.2.0.dist-info/WHEEL +5 -0
- pynode_flow-0.2.0.dist-info/entry_points.txt +3 -0
- pynode_flow-0.2.0.dist-info/licenses/LICENSE +21 -0
- pynode_flow-0.2.0.dist-info/scm_file_list.json +270 -0
- pynode_flow-0.2.0.dist-info/scm_version.json +8 -0
- pynode_flow-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Inject node - generates messages with configurable properties.
|
|
3
|
+
Similar to Node-RED's inject node.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import json
|
|
8
|
+
import time
|
|
9
|
+
import threading
|
|
10
|
+
from pynode.nodes.base_node import BaseNode, Info, MessageKeys
|
|
11
|
+
|
|
12
|
+
_info = Info()
|
|
13
|
+
_info.add_text("Generates messages with configurable properties. Can inject manually, once after a delay, or repeatedly at an interval. Similar to Node-RED's inject node.")
|
|
14
|
+
_info.add_header("Outputs")
|
|
15
|
+
_info.add_bullets(
|
|
16
|
+
("Output 0:", "Generated message with configured properties.")
|
|
17
|
+
)
|
|
18
|
+
_info.add_header("Trigger Options")
|
|
19
|
+
_info.add_bullets(
|
|
20
|
+
("Manual:", "Click the inject button on the node."),
|
|
21
|
+
("Once After:", "Inject once after a delay (in seconds) when workflow starts."),
|
|
22
|
+
("Repeat:", "Inject repeatedly at the specified interval (in seconds).")
|
|
23
|
+
)
|
|
24
|
+
_info.add_header("Property Types")
|
|
25
|
+
_info.add_bullets(
|
|
26
|
+
("String:", "Text value"),
|
|
27
|
+
("Number:", "Numeric value"),
|
|
28
|
+
("Boolean:", "true or false"),
|
|
29
|
+
("JSON:", "Parsed JSON object or array"),
|
|
30
|
+
("Timestamp:", "Current Unix timestamp (time.time())"),
|
|
31
|
+
("Env:", "Environment variable value")
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class InjectNode(BaseNode):
|
|
36
|
+
"""
|
|
37
|
+
Inject node - generates messages with configurable properties.
|
|
38
|
+
Similar to Node-RED's inject node.
|
|
39
|
+
"""
|
|
40
|
+
display_name = 'Inject'
|
|
41
|
+
icon = '⏱'
|
|
42
|
+
category = 'common'
|
|
43
|
+
color = '#C0DEED'
|
|
44
|
+
border_color = '#87A9C1'
|
|
45
|
+
text_color = '#000000'
|
|
46
|
+
input_count = 0
|
|
47
|
+
output_count = 1
|
|
48
|
+
info = str(_info)
|
|
49
|
+
ui_component = 'button'
|
|
50
|
+
ui_component_config = {
|
|
51
|
+
'icon': '▶',
|
|
52
|
+
'action': 'inject',
|
|
53
|
+
'tooltip': 'Inject'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# UI-triggerable actions (see BaseNode.actions)
|
|
57
|
+
actions = ['inject']
|
|
58
|
+
|
|
59
|
+
properties = [
|
|
60
|
+
{
|
|
61
|
+
'name': 'props',
|
|
62
|
+
'label': 'Message Properties',
|
|
63
|
+
'type': 'injectProps'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
'name': 'topic',
|
|
67
|
+
'label': 'Topic',
|
|
68
|
+
'type': 'text'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
'name': 'once',
|
|
72
|
+
'label': 'Inject once after',
|
|
73
|
+
'type': 'text',
|
|
74
|
+
'help': 'Delay in seconds (leave empty to disable)'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
'name': 'repeat',
|
|
78
|
+
'label': 'Repeat interval',
|
|
79
|
+
'type': 'text',
|
|
80
|
+
'help': 'Interval in seconds (leave empty to disable)'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
'name': 'inject',
|
|
84
|
+
'label': 'Inject',
|
|
85
|
+
'type': 'button',
|
|
86
|
+
'action': 'inject'
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
def __init__(self, node_id=None, name="inject"):
|
|
91
|
+
super().__init__(node_id, name)
|
|
92
|
+
self._timer_thread = None
|
|
93
|
+
self._stop_timer = False
|
|
94
|
+
self._once_timer = None
|
|
95
|
+
|
|
96
|
+
def _get_property_value(self, prop):
|
|
97
|
+
"""Convert a property definition to its actual value."""
|
|
98
|
+
value_type = prop.get('valueType', 'str')
|
|
99
|
+
raw_value = prop.get('value', '')
|
|
100
|
+
|
|
101
|
+
if value_type == 'date':
|
|
102
|
+
return time.time()
|
|
103
|
+
elif value_type == 'str':
|
|
104
|
+
return str(raw_value)
|
|
105
|
+
elif value_type == 'num':
|
|
106
|
+
try:
|
|
107
|
+
return float(raw_value)
|
|
108
|
+
except (ValueError, TypeError):
|
|
109
|
+
return 0
|
|
110
|
+
elif value_type == 'bool':
|
|
111
|
+
return raw_value in ('true', True, 'True', '1', 1)
|
|
112
|
+
elif value_type == 'json':
|
|
113
|
+
try:
|
|
114
|
+
return json.loads(raw_value) if raw_value else {}
|
|
115
|
+
except (json.JSONDecodeError, TypeError):
|
|
116
|
+
return {}
|
|
117
|
+
elif value_type == 'env':
|
|
118
|
+
return os.environ.get(str(raw_value), '')
|
|
119
|
+
else:
|
|
120
|
+
return raw_value
|
|
121
|
+
|
|
122
|
+
def _set_nested_property(self, obj, path, value):
|
|
123
|
+
"""Set a nested property in an object using dot notation.
|
|
124
|
+
|
|
125
|
+
e.g., _set_nested_property(msg, f'{MessageKeys.PAYLOAD}.data.value', 123)
|
|
126
|
+
sets msg[f'{MessageKeys.PAYLOAD}']['data']['value'] = 123
|
|
127
|
+
|
|
128
|
+
If a path segment already exists but is not a dict, it will be
|
|
129
|
+
replaced with a dict to allow nested properties.
|
|
130
|
+
"""
|
|
131
|
+
parts = path.split('.')
|
|
132
|
+
current = obj
|
|
133
|
+
|
|
134
|
+
for part in parts[:-1]:
|
|
135
|
+
if part not in current or not isinstance(current[part], dict):
|
|
136
|
+
current[part] = {}
|
|
137
|
+
current = current[part]
|
|
138
|
+
|
|
139
|
+
current[parts[-1]] = value
|
|
140
|
+
|
|
141
|
+
def inject(self):
|
|
142
|
+
"""
|
|
143
|
+
Manually trigger an injection.
|
|
144
|
+
"""
|
|
145
|
+
try:
|
|
146
|
+
msg = {}
|
|
147
|
+
|
|
148
|
+
# Set topic if configured
|
|
149
|
+
topic = self.config.get(MessageKeys.TOPIC, '')
|
|
150
|
+
if topic:
|
|
151
|
+
msg[MessageKeys.TOPIC] = topic
|
|
152
|
+
|
|
153
|
+
# Process all configured properties
|
|
154
|
+
props = self.config.get('props', [])
|
|
155
|
+
|
|
156
|
+
# Handle case where props might be empty or None
|
|
157
|
+
if not props:
|
|
158
|
+
props = []
|
|
159
|
+
|
|
160
|
+
for prop in props:
|
|
161
|
+
property_path = prop.get('property', MessageKeys.PAYLOAD)
|
|
162
|
+
value = self._get_property_value(prop)
|
|
163
|
+
self._set_nested_property(msg, property_path, value)
|
|
164
|
+
|
|
165
|
+
# Always send a message, even if it's empty (will get _msgid added)
|
|
166
|
+
msg = self.create_message(**msg)
|
|
167
|
+
self.send(msg)
|
|
168
|
+
except Exception as e:
|
|
169
|
+
self.report_error(f"Inject failed: {str(e)}")
|
|
170
|
+
|
|
171
|
+
def on_start(self):
|
|
172
|
+
"""
|
|
173
|
+
Start timers if configured.
|
|
174
|
+
"""
|
|
175
|
+
# Start the base node worker thread
|
|
176
|
+
super().on_start()
|
|
177
|
+
|
|
178
|
+
# Handle "inject once after delay"
|
|
179
|
+
once_delay = self.config.get('once', '')
|
|
180
|
+
if once_delay and str(once_delay).strip():
|
|
181
|
+
try:
|
|
182
|
+
delay_seconds = float(once_delay)
|
|
183
|
+
self._once_timer = threading.Timer(delay_seconds, self.inject)
|
|
184
|
+
self._once_timer.daemon = True
|
|
185
|
+
self._once_timer.start()
|
|
186
|
+
except (ValueError, TypeError):
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
# Handle "repeat interval"
|
|
190
|
+
repeat_interval = self.config.get('repeat', '')
|
|
191
|
+
if repeat_interval and str(repeat_interval).strip():
|
|
192
|
+
try:
|
|
193
|
+
interval_seconds = float(repeat_interval)
|
|
194
|
+
self._stop_timer = False
|
|
195
|
+
self._timer_thread = threading.Thread(
|
|
196
|
+
target=self._repeat_timer,
|
|
197
|
+
args=(interval_seconds,),
|
|
198
|
+
daemon=True
|
|
199
|
+
)
|
|
200
|
+
self._timer_thread.start()
|
|
201
|
+
except (ValueError, TypeError):
|
|
202
|
+
pass
|
|
203
|
+
|
|
204
|
+
def _repeat_timer(self, interval):
|
|
205
|
+
"""
|
|
206
|
+
Background timer for repeated injections.
|
|
207
|
+
Uses absolute timing to prevent drift.
|
|
208
|
+
"""
|
|
209
|
+
next_time = time.time() + interval
|
|
210
|
+
|
|
211
|
+
while not self._stop_timer:
|
|
212
|
+
current_time = time.time()
|
|
213
|
+
sleep_time = next_time - current_time
|
|
214
|
+
|
|
215
|
+
if sleep_time > 0:
|
|
216
|
+
time.sleep(sleep_time)
|
|
217
|
+
|
|
218
|
+
if not self._stop_timer:
|
|
219
|
+
self.inject()
|
|
220
|
+
# Schedule next injection at fixed interval from the scheduled time
|
|
221
|
+
next_time += interval
|
|
222
|
+
|
|
223
|
+
# If we're running behind, catch up by skipping to the next valid time
|
|
224
|
+
if next_time < time.time():
|
|
225
|
+
next_time = time.time() + interval
|
|
226
|
+
|
|
227
|
+
def on_stop(self):
|
|
228
|
+
"""
|
|
229
|
+
Stop all timers when workflow stops.
|
|
230
|
+
"""
|
|
231
|
+
# Stop base node worker thread
|
|
232
|
+
super().on_stop()
|
|
233
|
+
|
|
234
|
+
self._stop_timer = True
|
|
235
|
+
if self._once_timer and self._once_timer.is_alive():
|
|
236
|
+
self._once_timer.cancel()
|
|
237
|
+
if self._timer_thread and self._timer_thread.is_alive():
|
|
238
|
+
# Thread will stop on next iteration
|
|
239
|
+
pass
|
|
240
|
+
|
|
241
|
+
def on_close(self):
|
|
242
|
+
"""
|
|
243
|
+
Clean up when node is deleted.
|
|
244
|
+
"""
|
|
245
|
+
self.on_stop()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# No external dependencies - uses only Python standard library
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Join Node - combines multiple messages into one.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from typing import Any, Dict, List
|
|
7
|
+
from pynode.nodes.base_node import BaseNode, Info, MessageKeys
|
|
8
|
+
|
|
9
|
+
_info = Info()
|
|
10
|
+
_info.add_text("Combines multiple messages into a single output message. Similar to Node-RED's join node.")
|
|
11
|
+
_info.add_header("Inputs")
|
|
12
|
+
_info.add_bullets(
|
|
13
|
+
("Input 0:", "Messages to be combined.")
|
|
14
|
+
)
|
|
15
|
+
_info.add_header("Outputs")
|
|
16
|
+
_info.add_bullets(
|
|
17
|
+
("Output 0:", "Combined message with aggregated payloads.")
|
|
18
|
+
)
|
|
19
|
+
_info.add_header("Join Modes")
|
|
20
|
+
_info.add_bullets(
|
|
21
|
+
("Automatic:", "Send combined result after each message."),
|
|
22
|
+
("Count:", "Wait for N messages before combining."),
|
|
23
|
+
("Timeout:", "Combine messages after a time delay.")
|
|
24
|
+
)
|
|
25
|
+
_info.add_header("Combine Types")
|
|
26
|
+
_info.add_bullets(
|
|
27
|
+
("Array:", "payload becomes [msg1.payload, msg2.payload, ...]"),
|
|
28
|
+
("Object:", "Merge all message payloads into one object."),
|
|
29
|
+
("String:", "Concatenate all payloads as strings.")
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class JoinNode(BaseNode):
|
|
34
|
+
"""
|
|
35
|
+
Join Node - combines messages from multiple sources into a single output.
|
|
36
|
+
Similar to Node-RED's join node.
|
|
37
|
+
"""
|
|
38
|
+
display_name = 'Join'
|
|
39
|
+
icon = '🔗'
|
|
40
|
+
category = 'function'
|
|
41
|
+
color = '#E9967A'
|
|
42
|
+
border_color = '#CD853F'
|
|
43
|
+
text_color = '#000000'
|
|
44
|
+
input_count = 1
|
|
45
|
+
output_count = 1
|
|
46
|
+
info = str(_info)
|
|
47
|
+
|
|
48
|
+
properties = [
|
|
49
|
+
{
|
|
50
|
+
'name': 'mode',
|
|
51
|
+
'label': 'Mode',
|
|
52
|
+
'type': 'select',
|
|
53
|
+
'options': [
|
|
54
|
+
{'value': 'auto', 'label': 'Automatic (after each message)'},
|
|
55
|
+
{'value': 'count', 'label': 'After a fixed number of messages'},
|
|
56
|
+
{'value': 'time', 'label': 'After a timeout'}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
'name': 'count',
|
|
61
|
+
'label': 'Message Count',
|
|
62
|
+
'type': 'number',
|
|
63
|
+
'default': 2
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
'name': 'timeout',
|
|
67
|
+
'label': 'Timeout (seconds)',
|
|
68
|
+
'type': 'number',
|
|
69
|
+
'default': 1.0
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
'name': 'combine',
|
|
73
|
+
'label': 'Combine Into',
|
|
74
|
+
'type': 'select',
|
|
75
|
+
'options': [
|
|
76
|
+
{'value': 'array', 'label': 'Array (msg.payload = [msg1, msg2, ...])'},
|
|
77
|
+
{'value': 'object', 'label': 'Object (merge all messages)'},
|
|
78
|
+
{'value': 'string', 'label': 'String (concatenate)'}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
def __init__(self, node_id=None, name="join"):
|
|
84
|
+
super().__init__(node_id, name)
|
|
85
|
+
self.configure({
|
|
86
|
+
'mode': 'count',
|
|
87
|
+
'count': 2,
|
|
88
|
+
'timeout': 1.0,
|
|
89
|
+
'combine': 'array',
|
|
90
|
+
'drop_messages': False
|
|
91
|
+
})
|
|
92
|
+
self.message_buffer = []
|
|
93
|
+
self.first_message_time = None
|
|
94
|
+
|
|
95
|
+
def on_input(self, msg: Dict[str, Any], input_index: int = 0):
|
|
96
|
+
"""Buffer messages and combine them based on configuration."""
|
|
97
|
+
self.message_buffer.append(msg.copy())
|
|
98
|
+
|
|
99
|
+
if self.first_message_time is None:
|
|
100
|
+
self.first_message_time = time.time()
|
|
101
|
+
|
|
102
|
+
mode = self.config.get('mode', 'count')
|
|
103
|
+
should_send = False
|
|
104
|
+
|
|
105
|
+
if mode == 'auto':
|
|
106
|
+
should_send = True
|
|
107
|
+
elif mode == 'count':
|
|
108
|
+
count = self.get_config_int('count', 2)
|
|
109
|
+
if len(self.message_buffer) >= count:
|
|
110
|
+
should_send = True
|
|
111
|
+
elif mode == 'time':
|
|
112
|
+
timeout = self.get_config_float('timeout', 1.0)
|
|
113
|
+
if time.time() - self.first_message_time >= timeout:
|
|
114
|
+
should_send = True
|
|
115
|
+
|
|
116
|
+
if should_send:
|
|
117
|
+
self._send_combined()
|
|
118
|
+
|
|
119
|
+
def _send_combined(self):
|
|
120
|
+
"""Combine buffered messages and send."""
|
|
121
|
+
if not self.message_buffer:
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
combine_type = self.config.get('combine', 'array')
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
if combine_type == 'array':
|
|
128
|
+
# Combine into array of payloads
|
|
129
|
+
combined_payload = [msg.get(MessageKeys.PAYLOAD) for msg in self.message_buffer]
|
|
130
|
+
elif combine_type == 'object':
|
|
131
|
+
# Merge all messages into one object
|
|
132
|
+
combined_payload = {}
|
|
133
|
+
for msg in self.message_buffer:
|
|
134
|
+
payload = msg.get(MessageKeys.PAYLOAD)
|
|
135
|
+
if isinstance(payload, dict):
|
|
136
|
+
combined_payload.update(payload)
|
|
137
|
+
else:
|
|
138
|
+
# Use index as key if not a dict
|
|
139
|
+
combined_payload[f'msg_{len(combined_payload)}'] = payload
|
|
140
|
+
else: # string
|
|
141
|
+
# Concatenate payloads as strings
|
|
142
|
+
combined_payload = ' '.join(str(msg.get(MessageKeys.PAYLOAD, '')) for msg in self.message_buffer)
|
|
143
|
+
|
|
144
|
+
output_msg = self.create_message(
|
|
145
|
+
payload=combined_payload,
|
|
146
|
+
topic=self.message_buffer[0].get(MessageKeys.TOPIC, ''),
|
|
147
|
+
message_count=len(self.message_buffer)
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
self.send(output_msg)
|
|
151
|
+
except Exception as e:
|
|
152
|
+
self.report_error(f"Error combining messages: {e}")
|
|
153
|
+
finally:
|
|
154
|
+
# Clear buffer
|
|
155
|
+
self.message_buffer.clear()
|
|
156
|
+
self.first_message_time = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# No external dependencies - uses only Python standard library
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Label Filter Node - filters messages based on detection labels.
|
|
3
|
+
Passes through messages that contain detections matching allowed labels.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict, List
|
|
7
|
+
from pynode.nodes.base_node import BaseNode, Info, MessageKeys
|
|
8
|
+
|
|
9
|
+
_info = Info()
|
|
10
|
+
_info.add_text("Filters messages based on object detection class labels. Routes messages to different outputs based on whether they contain matching detections.")
|
|
11
|
+
_info.add_header("Inputs")
|
|
12
|
+
_info.add_bullets(
|
|
13
|
+
("Input 0:", "Message with detection data (e.g., from inference node).")
|
|
14
|
+
)
|
|
15
|
+
_info.add_header("Outputs")
|
|
16
|
+
_info.add_bullets(
|
|
17
|
+
("Output 0:", "Messages with detections matching allowed labels."),
|
|
18
|
+
("Output 1:", "Messages without matching labels.")
|
|
19
|
+
)
|
|
20
|
+
_info.add_header("Match Modes")
|
|
21
|
+
_info.add_bullets(
|
|
22
|
+
("Any:", "Pass if any detection matches any allowed label."),
|
|
23
|
+
("All:", "Pass only if all allowed labels are present in detections.")
|
|
24
|
+
)
|
|
25
|
+
_info.add_header("Options")
|
|
26
|
+
_info.add_bullets(
|
|
27
|
+
("Labels:", "Comma-separated list of allowed labels (e.g., 'person, car, dog')."),
|
|
28
|
+
("Case Sensitive:", "Whether label matching is case-sensitive."),
|
|
29
|
+
("Filter Detections:", "Remove non-matching detections from output message.")
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class LabelFilterNode(BaseNode):
|
|
34
|
+
"""
|
|
35
|
+
Label Filter node - filters messages based on detection class labels.
|
|
36
|
+
Only passes through messages containing detections that match the allowed labels.
|
|
37
|
+
"""
|
|
38
|
+
display_name = 'Label Filter'
|
|
39
|
+
icon = '🏷️'
|
|
40
|
+
category = 'vision'
|
|
41
|
+
color = '#C7E9C0'
|
|
42
|
+
border_color = '#74C476'
|
|
43
|
+
text_color = '#000000'
|
|
44
|
+
input_count = 1
|
|
45
|
+
output_count = 2 # Output 1: matched, Output 2: unmatched
|
|
46
|
+
info = str(_info)
|
|
47
|
+
|
|
48
|
+
DEFAULT_CONFIG = {
|
|
49
|
+
'labels': 'person, car',
|
|
50
|
+
'match_mode': 'any',
|
|
51
|
+
'case_sensitive': False,
|
|
52
|
+
'filter_detections': True,
|
|
53
|
+
'detections_path': 'payload.detections'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
properties = [
|
|
57
|
+
{
|
|
58
|
+
'name': 'labels',
|
|
59
|
+
'label': 'Allowed Labels',
|
|
60
|
+
'type': 'text',
|
|
61
|
+
'default': DEFAULT_CONFIG['labels'],
|
|
62
|
+
'help': 'Comma-separated list of labels to allow (e.g., "person, car, dog")'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
'name': 'match_mode',
|
|
66
|
+
'label': 'Match Mode',
|
|
67
|
+
'type': 'select',
|
|
68
|
+
'options': [
|
|
69
|
+
{'value': 'any', 'label': 'Any label matches'},
|
|
70
|
+
{'value': 'all', 'label': 'All labels must be present'}
|
|
71
|
+
],
|
|
72
|
+
'default': DEFAULT_CONFIG['match_mode'],
|
|
73
|
+
'help': 'How to match multiple labels'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
'name': 'case_sensitive',
|
|
77
|
+
'label': 'Case Sensitive',
|
|
78
|
+
'type': 'checkbox',
|
|
79
|
+
'default': DEFAULT_CONFIG['case_sensitive'],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
'name': 'filter_detections',
|
|
83
|
+
'label': 'Filter Detections Array',
|
|
84
|
+
'type': 'checkbox',
|
|
85
|
+
'default': DEFAULT_CONFIG['filter_detections'],
|
|
86
|
+
'help': 'Remove non-matching detections from the output'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
'name': 'detections_path',
|
|
90
|
+
'label': 'Detections Path',
|
|
91
|
+
'type': 'text',
|
|
92
|
+
'default': DEFAULT_CONFIG['detections_path'],
|
|
93
|
+
'help': f'Path to detection(s) in message (e.g., "{DEFAULT_CONFIG["detections_path"]}")'
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
def __init__(self, node_id=None, name="label filter"):
|
|
98
|
+
super().__init__(node_id, name)
|
|
99
|
+
|
|
100
|
+
def _parse_labels(self) -> List[str]:
|
|
101
|
+
"""Parse the comma-separated labels config into a list."""
|
|
102
|
+
labels_str = self.config.get('labels', '')
|
|
103
|
+
case_sensitive = self.config.get('case_sensitive', False)
|
|
104
|
+
|
|
105
|
+
labels = [l.strip() for l in labels_str.split(',') if l.strip()]
|
|
106
|
+
|
|
107
|
+
if not case_sensitive:
|
|
108
|
+
labels = [l.lower() for l in labels]
|
|
109
|
+
|
|
110
|
+
return labels
|
|
111
|
+
|
|
112
|
+
def on_input(self, msg: Dict[str, Any], input_index: int = 0):
|
|
113
|
+
"""
|
|
114
|
+
Filter messages based on detection labels.
|
|
115
|
+
Output 0: Messages with matching labels
|
|
116
|
+
Output 1: Messages without matching labels
|
|
117
|
+
"""
|
|
118
|
+
allowed_labels = self._parse_labels()
|
|
119
|
+
if not allowed_labels:
|
|
120
|
+
# No labels configured, pass everything through output 0
|
|
121
|
+
self.send(msg, 0)
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
detections_path = self.config.get('detections_path', self.DEFAULT_CONFIG['detections_path'])
|
|
125
|
+
detection_data = self._get_nested_value(msg, detections_path)
|
|
126
|
+
|
|
127
|
+
if detection_data is None:
|
|
128
|
+
# No detection found, send to unmatched output
|
|
129
|
+
self.send(msg, 1)
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
# Handle both single detection (dict) and array of detections (list)
|
|
133
|
+
if isinstance(detection_data, dict):
|
|
134
|
+
detections = [detection_data]
|
|
135
|
+
is_single = True
|
|
136
|
+
elif isinstance(detection_data, list):
|
|
137
|
+
detections = detection_data
|
|
138
|
+
is_single = False
|
|
139
|
+
else:
|
|
140
|
+
# Invalid detection data, send to unmatched output
|
|
141
|
+
self.send(msg, 1)
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
case_sensitive = self.config.get('case_sensitive', self.DEFAULT_CONFIG['case_sensitive'])
|
|
145
|
+
match_mode = self.config.get('match_mode', self.DEFAULT_CONFIG['match_mode'])
|
|
146
|
+
filter_detections = self.config.get('filter_detections', self.DEFAULT_CONFIG['filter_detections'])
|
|
147
|
+
|
|
148
|
+
# Get labels from detections
|
|
149
|
+
detected_labels = set()
|
|
150
|
+
matching_detections = []
|
|
151
|
+
|
|
152
|
+
for detection in detections:
|
|
153
|
+
label = detection.get('class_name', detection.get('label', detection.get('class', '')))
|
|
154
|
+
if not case_sensitive:
|
|
155
|
+
label = label.lower() if label else ''
|
|
156
|
+
|
|
157
|
+
detected_labels.add(label)
|
|
158
|
+
|
|
159
|
+
if label in allowed_labels:
|
|
160
|
+
matching_detections.append(detection)
|
|
161
|
+
|
|
162
|
+
# Check if we have a match based on mode
|
|
163
|
+
has_match = False
|
|
164
|
+
if match_mode == 'any':
|
|
165
|
+
# At least one allowed label must be present
|
|
166
|
+
has_match = bool(detected_labels & set(allowed_labels))
|
|
167
|
+
else: # 'all'
|
|
168
|
+
# All allowed labels must be present
|
|
169
|
+
has_match = set(allowed_labels).issubset(detected_labels)
|
|
170
|
+
|
|
171
|
+
if has_match:
|
|
172
|
+
# Modify msg directly - send() handles deep copying
|
|
173
|
+
if filter_detections and matching_detections:
|
|
174
|
+
# Replace detections with only matching ones
|
|
175
|
+
if MessageKeys.PAYLOAD in msg and isinstance(msg[MessageKeys.PAYLOAD], dict):
|
|
176
|
+
# For single detection, keep as single; for array, keep as array
|
|
177
|
+
if is_single:
|
|
178
|
+
self._set_nested_value(msg, detections_path, matching_detections[0])
|
|
179
|
+
else:
|
|
180
|
+
self._set_nested_value(msg, detections_path, matching_detections)
|
|
181
|
+
# Update detection count if present
|
|
182
|
+
if 'detection_count' in msg[MessageKeys.PAYLOAD]:
|
|
183
|
+
msg[MessageKeys.PAYLOAD]['detection_count'] = len(matching_detections)
|
|
184
|
+
|
|
185
|
+
self.send(msg, 0)
|
|
186
|
+
else:
|
|
187
|
+
# No match, send to second output (msg passes through with all properties preserved)
|
|
188
|
+
self.send(msg, 1)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# No external dependencies - uses only Python standard library
|