Author: Abhinav Patel
Welcome all, to the DataWeave series for Mule 4.
If you have not gone through the previous article-1 and article-2, I would recommend you to go through it first, to get a basic understanding of Dataweave. In this blog, we will focus on the working of mapObject and other object operations, to get the desired output. Also, you are recommended to check for the output type after performing each step so as to get a better understanding.
We are being provided with a dataset that contains the information of distance required to stop a vehicle at a given speed. For a given speed, the experiment was performed several times and the data was recorded in a CSV file.
You can get the data from here.
Now, this raw dataset is made available to you for further analysis and to determine the average distance required to stop a vehicle at any given speed.
These are operations involved to meet the given requirement:
Note: These steps are performed once the file is saved in the src/main/resource folder of a mule project in the studio. Also, all the transformations are performed using the standalone Transform Message Processor.
- For simplicity, I will be saving the entire data from CSV to a variable.
Before moving ahead, lets quickly do type coercing for safety. This would not have any effect on output but will make sure that the input for the next operation is an Array. #Best_Practise
Let’s now group the available raw data set so that we have organized data we are aware of the frequency of observation carried out to get the data at any given speed.
**At this stage, the output will be an object.
4. Now let’s quickly try to get the average distance required for a vehicle to stop at a given speed, and also display the analysis result in a human-readable format.
5. In the last step, you are expected to arrange the data in the increasing order of speed.
I hope you got to learn something new from this walkthrough.
Also if you have any use case, feel free to share it at firstname.lastname@example.org.