This example defines a Python calculation adapter that sends data to and from the WaveApps host application.
- Modify
data_proxy.py,__init__function, to define outputs and add any custom configuration parameters for calculation algorithm (these will be synchronized to WaveApps C# proxy adapter). - Modify
process_datato implement desired calculation algorithm.
python main.py <hostname> <wave_apps_port> <data_pub_port># Connect to a WaveApps proxy adapter running on localhost port 7198 and
# host data publication on port 7199. These ports must be unique for each
# Python calculation adapter.
python main.py localhost 7198 7199The example python calculation will:
- Connect to the specified WaveApps adapter (
<hostname>:<wave_apps_port>) - Establish a publisher for calculated data (
<data_pub_port>) - Subscribe to frequency measurements using filter:
FILTER ActiveMeasurements WHERE SignalType = 'FREQ' - Receive incoming measurements, grouped by timestamp to the nearest second
- Process grouped data in one-second windows
- Calculate and display average frequency for each second of data
- Trigger an event if frequency is out of range
- Timestamp Grouping: Groups measurements by whole seconds with subsecond alignment
- Data Buffering: Maintains 5-second measurement windows for processing
- Time Validation: Filters data based on configurable lag time (2 seconds) and lead time (2 seconds)
- Downsampling Detection: Tracks and reports when data rate exceeds processing capacity
- Thread-Safe Processing: Uses locks to ensure data integrity in multi-threaded environment
This example is configured with:
- Measurement window size: 5 seconds
- Samples per second: 3000
- Lag time: 2.0 seconds
- Lead time: 2.0 seconds
When connected to a publisher, you should see:
- "Measurement reader established" message
- "Receiving measurements..." when data starts arriving
- Average frequency calculations for each second of data
Example output:
Receiving measurements...
Average frequency for 3000 values in second 45: 60.001234 Hz
Average frequency for 3000 values in second 46: 59.998765 Hz
The example includes a process_data callback function that:
- Receives one-second buffers of time-aligned measurements
- Filters frequency values to reasonable range (59.95 to 60.05 Hz)
- Calculates average frequency across all valid measurements
- Demonstrates how to access measurement values, timestamps, and signal IDs
- Shows how to iterate through grouped measurement data
Press Enter to gracefully disconnect and shut down the subscriber.