AI mappings
We just published the pre-release 6.0.0 of the Dynamic Mapper with the core improvement that mappings can be generated now fully automated by just a single click, leveraging AI agents in the background.
Auto-generating mappings is supported for using graphical mappings (JSONata) and JavaScript mappings.
Example Output for Code-mapping
Based on your mapping configuration, I’ll provide you with a JavaScript function that extracts data from the source template and creates the appropriate substitutions for the target template. Here’s the implementation:
function extractFromSource(ctx) { // This is the source message as json const sourceObject = JSON.parse(ctx.getPayload()); tracePayload(ctx); // Create a new SubstitutionResult const result = new SubstitutionResult(); // Extract measurements array const measurements = sourceObject['mea']; if (!measurements || !Array.isArray(measurements)) { console.log("No measurements array found in source"); return result; } // Process each measurement entry for (let i = ( measurements.length; i++) { const measurement = measurements[i]; const values = measurement.values; if (!values || !Array.isArray(values)) { console.log(`No values array found for measurement ${i}`); continue; } // Process each value in the measurement for (let j = 0; j < values.length; j++) { const valueEntry = values[j]; // Validate value entry if (valueEntry.value === undefined || valueEntry.timestamp === undefined) { console.log(`Invalid value entry at measurement ${i}, value ${j}`); continue; } // Create the measurement fragment structure const processLoadFragment = { L: { value: valueEntry.value, unit: "%" } }; // Add the measurement fragment with expandArray=true const measurementValue = new SubstitutionValue( processLoadFragment, TYPE.OBJECT, RepairStrategy.DEFAULT, true // expandArray=true to create multiple measurement documents ); addSubstitution(result, 'c8y_ProcessLoadMeasurement', measurementValue); // Convert timestamp from milliseconds to ISO format const isoTime = new Date(valueEntry.timestamp).toISOString(); const timeValue = new SubstitutionValue( isoTime, TYPE.TEXTUAL, RepairStrategy.DEFAULT, true // expandArray=true to match with measurements ); addSubstitution(result, 'time', timeValue); // Add measurement type const typeValue = new SubstitutionValue( 'c8y_ProcessLoadMeasurement', TYPE.TEXTUAL, RepairStrategy.DEFAULT, true // expandArray=true to match with measurements ); addSubstitution(result, 'type', typeValue); } } // Define Device Identifier from topic level (same for all measurements) const deviceIdentifier = new SubstitutionValue( sourceObject['_TOPIC_LEVEL_'][1], TYPE.TEXTUAL, RepairStrategy.DEFAULT, false // Don't expand - same device for all measurements ); addSubstitution(result, ctx.getGenericDeviceIdentifier(), deviceIdentifier); return result; }
Key Features of This Implementation:
Nested Array Processing: The function processes both the mea array and the nested values arrays within each measurement entry.
expandArray Usage:
- expandArray=true for measurement data, time, and type to create multiple separate measurement documents
- expandArray=false for device identifier since it’s the same for all measurements
Data Transformation:
- Extracts value from each measurement and maps it to c8y_ProcessLoadMeasurement.L.value
- Adds the unit “%” as specified in the target template
- Converts timestamps from milliseconds to ISO format
- Sets the measurement type consistently
- Device Identification: Uses the second element from TOPIC_LEVEL array (device_best_01) as the device identifier.
Expected Output:
With your source data, this will generate 2 separate measurement documents:
Document 1:
{ "c8y_ProcessLoadMeasurement": { "L": { "value": 4.6, "unit": "%" } }, "time": "2022-03-29T14:04:45.347Z", "type": "c8y_ProcessLoadMeasurement", "source": { "id": "device_best_01" } }
Document 2:
{ "c8y_ProcessLoadMeasurement": { "L": { "value": 5.6, "unit": "%" } }, "time": "2022-03-29T14:21:25.347Z", "type": "c8y_ProcessLoadMeasurement", "source": { "id": "device_best_01" } }
The function includes proper error handling and validation to ensure robust processing of the measurement data.
Why pre-release?
We decided to firstly publish a pre-release to collect feedback on how the AI agents are performing for different use cases. Be assured we already tested a lot of templates and tried to optimize the agents, but there might still be templates where they don’t produce the expected results.
If you recognize any issues, please provide feedback by either adding a comment here or creating an issue.
Other changes
Besides that, we also made some other improvements like:
- Pre-builds for microservice
- Responsiveness of UI
- Renaming of labels
- and a lot more