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

This widget could not be displayed.

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 widget could not be displayed.

This is pretty awesome Igor! Thanks for sharing!

This widget could not be displayed.

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
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

509 views 7 6
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