When using
#AWSStepFunctions, don't forget a healthy side of
#JSONata! Here is an example of reducing transitions.
$states.result.Items[type.S = 'CSAT'].csatEvent.S ~>
$map(function($v) {$number($v)}) ~> $average ~>
$round(2)
This query is calculating the average CSAT (Customer Satisfaction) score for an event, rounded to 2 decimal places. Let's break it down:
1.
$states.result.Items - Starts by accessing the Items array within the result object of the states variable.
2. [type.S = 'CSAT'] - Filters the Items array to only include elements where the type.S attribute equals 'CSAT'.
3. .csatEvent.S - From the filtered items, extracts the S (string) attribute of csatEvent. This creates an array of CSAT string values.
4. ~>
$map(function($v) {$number($v)}) - The ~> is a "pipeline" operator that passes the result to the next function. Here, it maps each string value to a number using the
$number function, converting the array of strings to an array of numbers.
5. ~> $average - Calculates the average of all the numeric CSAT values.
6. ~>
$round(2) - Rounds the average to 2 decimal places.