Calculate JAWS runs passing per compute site
The snippet can be accessed without any authentication.
Authored by
Will Holtz
$ ./jaws_stats.sh --help
USAGE: ./jaws_stats.sh [days] [jq_select_terms]
days: evaluate over last N days of history (default: 30)
jq_select_terms: a boolean expression that is passed to the jq
select() function (default: true)
EXAMPLE: ./jaws_stats.sh 7 '.tag//"" | startswith("DAP-")'
jaws_stats.sh 2.09 KiB
#!/bin/bash
set -euo pipefail
if [ "$#" -gt 2 ] || [ "${1-}" = "--help" ]; then
>&2 echo "USAGE: ${0} [days] [jq_select_terms]"
>&2 echo " days: evaluate over last N days of history (default: 30)"
>&2 echo " jq_select_terms: a boolean expression that is passed to the jq"
>&2 echo " select() function (default: true)"
>&2 echo ""
>&2 echo "EXAMPLE: ${0} 7 '.tag//\"\" | startswith(\"DAP-\")'"
exit 1
fi
days="${1:-30}"
jq_select_terms="${2:-true}"
jaws_image='doejgi/jaws-client:latest'
if which jaws &> /dev/null; then
jaws=jaws
elif which apptainer &> /dev/null; then
jaws="apptainer --silent run docker://${jaws_image} jaws"
elif which shifter &> /dev/null; then
jaws="shifter --image ${jaws_image} jaws"
elif which docker &> /dev/null; then
jaws="docker run -it --rm ${jaws_image} jaws"
else
>&2 echo "ERROR: Cannot find 'jaws' or a container execution program."
exit 2
fi
get_num_result() {
# get_run_result site jq_select_terms json_file result_value
jq ".[] | select((.result == \"${4}\")
and (.compute_site_id == \"${1}\")
and (${2})
) | .id" "${3}" \
| wc -l
}
get_site_stats() {
# get_site_stats site jq_select_terms json_file
local pass fail total percent_pass
fail="$(get_num_result "${1}" "${2}" "${3}" "failed")"
pass="$(get_num_result "${1}" "${2}" "${3}" "succeeded")"
total=$((pass + fail))
if [ "${total}" != "0" ]; then
percent_pass="$(echo "scale=1; ${pass}*100/(${total})" | bc)"
else
percent_pass='null'
fi
jq --null-input \
--arg site "${1}" \
--argjson total "${total}" \
--argjson percent_pass "${percent_pass}" \
'{"compute_site_id": $site,
"total": $total,
"percent_pass": $percent_pass}'
}
runs_file="$(mktemp)"
trap 'rm -f -- "$runs_file"' EXIT
$jaws history --days "${days}" --all > "${runs_file}"
mapfile -t compute_sites < <( jq -r '.[] | .compute_site_id' "${runs_file}" | sort -u )
(
for site in "${compute_sites[@]}"; do
get_site_stats "${site}" "${jq_select_terms}" "${runs_file}"
done
) \
| jq -s .
Please register or sign in to comment