How To Generate Summary Statistics Based On Team Calendars in Confluence

Igor Kucherenko August 3, 2013

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

1 vote
Answer accepted
Igor Kucherenko August 22, 2013

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

0 votes
Sherif Mansour
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 23, 2013

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.

0 votes
Ryan Goodwin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2013

This is pretty awesome Igor! Thanks for sharing!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events