Skip to content

Instantly share code, notes, and snippets.

@docteurklein
Last active October 19, 2018 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docteurklein/0dd2fe5edb625a308c0258994ec26d5e to your computer and use it in GitHub Desktop.
Save docteurklein/0dd2fe5edb625a308c0258994ec26d5e to your computer and use it in GitHub Desktop.
generate burndown charts with trello, R and jq
export TRELLO_TOKEN='<your trello token>' # found in web cookie
export TRELLO_DONE_ID='<the trello internal id of the "Done" list>'

curl -H "Cookie: token=$TRELLO_TOKEN;" -sL trello.com/b/2NFnHkvl.json \
  | ./plot.sh 2018-06-01 2018-11-01 true | ./burndown.r "$(date --iso -d '+2 year')" && xdg-open burndown.svg
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
library('plan')
burndown <- read.burndown(file('stdin', 'r'))
svg(file='burndown.svg', width = 20, height = 10)
plot(burndown, t.stop=args[1])
dev.off()
#!/usr/bin/env sh
set -euo pipefail
json=$(cat -)
with_detail=${3:-''}
start=$1
deadline=$2
now=$(date --iso)
total_cards=$(jq -r '.cards | map(select(.closed == false))|length' <<< $json)
done_cards=$(jq --arg TRELLO_DONE_ID $TRELLO_DONE_ID -r '.cards | map(select(.closed == false and .idList == $TRELLO_DONE_ID))|length' <<< $json)
left_cards=$(($total_cards - $done_cards))
progress=$(bc -l <<< "scale=2; $done_cards / $total_cards * 100")
#total_days=$(bc -l <<< "$(date -d $deadline +%s) - $(date -d $start +%s) / (24*3600)")
#current_days=$(bc -l <<< "$(date -d $now +%s) - $(date -d $start +%s) / (24*3600)")
#days_left=$(bc -l <<< "$(date -d $deadline +%s) - $(date -d $now +%s) / (24*3600)")
avg_card_duration=$(bc -l <<< "scale=2; $done_cards / $progress")
estimated_days_left=$(printf %2.f $(bc -l <<< "scale=2; $avg_card_duration * $left_cards"))
echo "Start, $start"
echo "Deadline, $deadline"
echo "Key, Description, Effort"
if [ $with_detail ]; then
echo $json | jq -r '.cards | map(select(.closed == false)) | to_entries | .[] | "\(.key + 1), \(.value.url|sub(".*/\\d+-"; "")), 1"'
echo "Key, Done, Time"
echo $json \
| jq --arg TRELLO_DONE_ID $TRELLO_DONE_ID -r '.cards | map(select(.closed == false and .idList == $TRELLO_DONE_ID)) | to_entries | .[] |"\(.key + 1), 100, \(.value.dateLastActivity | sub("\\.[0-9]+Z$"; "Z"))"'
else
echo "1, project, $total_cards"
echo "Key, Done, Time"
unit_percent=$(bc -l <<< "scale=2; 100 / $total_cards")
echo $json \
| jq --arg unit_percent $unit_percent --arg TRELLO_DONE_ID $TRELLO_DONE_ID -r '.cards | map(select(.closed == false and .idList == $TRELLO_DONE_ID)) | to_entries | .[] |"1, \((.key + 1) * ($unit_percent | tonumber)), \(.value.dateLastActivity | sub("\\.[0-9]+Z$"; "Z"))"'
fi
echo "total cards: $total_cards" >> /dev/stderr
echo "done cards: $done_cards" >> /dev/stderr
echo "progress: ${progress}%" >> /dev/stderr
echo "avg card duration: $avg_card_duration days" >> /dev/stderr
echo "estimated end in: $estimated_days_left days ($(date --iso -d "+${estimated_days_left} days"))" >> /dev/stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment