How To Generate Summary Statistics Based On Team Calendars in Confluence

If you use Team Calendars to track your team's out of the office, vacations, sick leaves events.

Here is an example how to calculate summary per employee and present it on your Confluence.

Here I use CSV Macro from Bob Swift Table Plugin for Confluence . The idea is the following:

  1. Get the subscription link from each Calendar, by clicking "Subscribe"
  2. Download ICS file from the link
  3. Convert ICS to CSV
  4. Import CSV file from file system or remote host, using CSV macro and get table on your Confluence page
  5. Wrap up this CSV macro with Chart macro and you have graphs

To do this conversion I use another host than Confluence host. This host is running on FreeBSD. So the script below works pretty well on FreeBSD, using set of built-in shell utilities so you don't need to install anything else:

#!/bin/sh

sed -e 's/^M//' $1 |egrep "^BEGIN:VEVENT|^DTSTART;|^DTEND;|^SUMMARY|^END:VEVENT'| sed -e 's/^SUMMARY:\(.*\):\(.*\)/SUMMARY:\1/' |cut -d':' -f1-2 | sed -e 's/^\(DTSTART\);\(.*\):\(.*\)/\1:\3/' | sed -e 's/^\(DTEND\);\(.*\):\(.*\)/\1:\3/' | paste -d '|' - - - - - | grep ":`date "+%Y"`" | sed 's/BEGIN:VEVENT|DTSTART://' | sed 's/DTEND://' | sed 's/SUMMARY://' | sed 's/|END:VEVENT//' | sed -e 's/^\([[:digit:]]*\)T\([[:digit:]]*\)|\([[:digit:]]*\)T\([[:digit:]]*\)|\([[:alpha:]]*\)/\1\2|\3\4|\5/'|sed -e 's/^\([[:digit:]]\{8\}\)|\([[:digit:]]\{8\}\)|\(.*\)/\1000000|\2000000|\3/'|awk -F'|' 'BEGIN { OFS = "|" } { time1="date -j -f \"%Y%m%d%H%M%S\" "$1" \+\"%s\""; time2="date -j -f \"%Y%m%d%H%M%S\" "$2" \+\"%s\""; time1 | getline epoc1;close(time1); time2 | getline epoc2; close(time2); $2=epoc2-epoc1; print $3,$2}'|awk -F'|' '{array[$1]+=$2} END { for (i in array) {print i"|" array[i]}}'| sort -k 2 -n -r -t'|' | awk -F'|' '{S=$2; printf $1","; printf "%d,%d,%d\n",S/86400,S%(86400)/3600,S%3600/60}'

3 answers

1 accepted

Updated script to be compatible with Team Calendars 4.0.1 .

#!/bin/sh

sed -e 's/^M//' $1 |egrep '^BEGIN:VEVENT|^DTSTART;|^DTEND;|^SUMMARY|^END:VEVENT'| sed -e 's/^SUMMARY:\(.*\):\(.*\)/SUMMARY:\1/' |cut -d':' -f1-2 | sed -e 's/^\(DTSTART\);\(.*\):\(.*\)/\1:\3/' | sed -e 's/^\(DTEND\);\(.*\):\(.*\)/\1:\3/' | paste -d '|' - - - - - | awk -F'|' 'BEGIN { OFS="|"; } { if ($2 ~ /SUMMARY:.*/) {print $1,$4,$3,$2,$5} else {print} }' | awk -F'|' 'BEGIN { OFS="|"; } { if ($2 ~ /DTEND:.*/) {print $1,$3,$2,$4,$5} else {print} }'| awk '!x[$0]++' | grep ":`date "+%Y"`" | sed 's/BEGIN:VEVENT|DTSTART://' | sed 's/DTEND://' | sed 's/SUMMARY://' | sed 's/|END:VEVENT//' | sed -e 's/^\([[:digit:]]*\)T\([[:digit:]]*\)|\([[:digit:]]*\)T\([[:digit:]]*\)|\([[:alpha:]]*\)/\1\2|\3\4|\5/'|sed -e 's/^\([[:digit:]]\{8\}\)|\([[:digit:]]\{8\}\)|\(.*\)/\1000000|\2000000|\3/'|awk -F'|' 'BEGIN { OFS = "|" } { time1="date -j -f \"%Y%m%d%H%M%S\" "$1" \+\"%s\""; time2="date -j -f \"%Y%m%d%H%M%S\" "$2" \+\"%s\""; time1 | getline epoc1;close(time1); time2 | getline epoc2; close(time2); $2=epoc2-epoc1; print $3,$2}'|awk -F'|' '{array[$1]+=$2} END { for (i in array) {print i"|" array[i]}}'| sort -k 2 -n -r -t'|' | awk -F'|' '{S=$2; printf $1","; printf "%d,%d,%d\n",S/86400,S%(86400)/3600,S%3600/60}'

to enter "^M" in this script, type ctrl-v ctrl-m

This is pretty awesome Igor! Thanks for sharing!

0 vote

My gosh! Crazy, but amazing work, Igor! WOW. Can I send you a Team Calendars t-shirt? :-)

Email me with your address (and size) details - sherif at atlassian dot com.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

377 views 20 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you