API fun with jq

I needed a way to subtract an offset from all data points on goal.

I ended up with the following one-liner, which might be useful to other people. Basically it’s a generalized version of the scale datapoints feature, except that it doesn’t touch the road at all. That might be a fun extension…

username=...
auth_token=...
goal=test
api=https://www.beeminder.com/api/v1/
curl -s -X GET $api/users/$username/goals/$goal/datapoints.json?auth_token=$auth_token | jq -c '.[] | {value: (.value + .999), id}' | while read -r json; do id=$(jq -r '.id' < <(echo $json)); curl -s -X PUT $api/users/$username/goals/$goal/datapoints/$id.json?auth_token=$auth_token --header "Content-Type: application/json" -d $json &>/dev/null; sleep 0.5; done

And here’s sort of a repost calculating a parametrised version of the urgency_load metric:

param=7; curl -s -X GET https://www.beeminder.com/api/v1/users/$username/goals.json?auth_token=$auth_token | jq '[.[] | select(.won | not) | select(.safebuf < '$param') | '$param' - .safebuf ] | add'
4 Likes