How To Generate Summary Statistics Based On Team Calendars in Confluence
Asked by Igor Kucherenko:

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

![](../../upfiles/team_calendars.png)

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

Here I use [CSV Macro](https://bobswift.atlassian.net/wiki/display/TBL/CSV+Macro "CSV Macro") from [Bob Swift Table Plugin for Confluence](https://bobswift.atlassian.net/wiki/display/TBL/Table+Plugin+for+Confluence "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/shsed -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}'
```

![](../../upfiles/absences.png)


Answers:
author: Igor Kucherenko
body: Updated script to be compatible with Team Calendars 4.0.1 .

```
#!/bin/shsed -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


author: Sherif Mansour
body: 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.


author: Ryan Goodwin
body: This is pretty awesome Igor! Thanks for sharing!


Tags: csv

team-calendars-for-confluence