#!/bin/bash if [[ $# -ne 2 || "$1" == '--help' ]] then echo "Usage: $0 PROJECT DURATION" >&2 echo 'Requests the PROJECT statistics from the AT tracker twice DURATION seconds apart, and calculates the average returned item size for each user within that window.' >&2 echo 'Output consists of lines of username SPACE SIZE, sorted by size ascending.' >&2 exit 1 fi project="$1" declare -i duration="$2" { curl -s "https://legacy-api.arpa.li/${project}/stats.json" | tr -d '\n' echo sleep ${duration} curl -s "https://legacy-api.arpa.li/${project}/stats.json" | tr -d '\n' echo } \ | python3 -c 'import json,sys;o0=json.loads(sys.stdin.readline());o1=json.loads(sys.stdin.readline());[print(k,(o1["downloader_bytes"][k]-o0["downloader_bytes"][k])/(o1["downloader_count"][k]-o0["downloader_count"][k])) for k in o0["downloaders"] if o1["downloader_count"][k] != o0["downloader_count"][k]]' \ | sort -k2,2n