Other Operations¶
Calculating averages¶
Calculate the average of one numeric property across a list of records.
jq¶
echo '[{"score":90},{"score":85},{"score":95}]' |
jq 'map(.score) | add / length'
JFTL¶
"$py=sum([x['score'] for x in _]) / len(_)"
Output¶
90
Complete JFTL example¶
{
"main": { "$": true, "data": "$_datasets.input", "out":
"$py=sum([x['score'] for x in _]) / len(_)"
},
"datasets": {
"input": [
{ "score": 90 },
{ "score": 85 },
{ "score": 95 }
]
}
}
Generating histogram bins¶
Group numeric observations into bins and count the number of observations in each bin.
jq¶
echo '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]' |
jq 'group_by((. / 5 | floor) * 5) | map({bin: ((.[0] / 5 | floor) * 5), count: length})'
JFTL¶
TBD
Output¶
[
{ "bin": 0, "count": 4 },
{ "bin": 5, "count": 5 },
{ "bin": 10, "count": 5 },
{ "bin": 15, "count": 1 }
]
Complete JFTL example¶
TBD