-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotateMeetingCosts.gs
47 lines (42 loc) · 2.11 KB
/
annotateMeetingCosts.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function annotateMeetingCosts() {
var daysToAnnotateFromNow = 7;
// TODO Adjust this to whatever the average hourly rate in your company is
var averageHourlyRate = 100;
// TODO Adjust this to the ID of your calendar
doAnnotateMeetingCosts('YourCalendarID', 2, daysToAnnotateFromNow, averageHourlyRate);
}
function doAnnotateMeetingCosts(calendarId, minNumberOfParticipants, daysToAnnotateFromNow, averageHourlyRate) {
var fromDate = new Date();
fromDate.setTime(Date.now());
var toDate = new Date();
toDate.setTime(fromDate.getTime() + 1000 * 60 * 60 * 24 * daysToAnnotateFromNow);
var calendar = CalendarApp.getCalendarById(calendarId);
var events = calendar.getEvents(fromDate, toDate);
for (var i = 0; i < events.length; i++) {
var event = events[i];
var creators = event.getCreators();
if (creators.indexOf(calendarId) < 0) {
Logger.log("Skipping event " + event.getTitle() + ", because " + calendarId + " is not the creator");
continue;
}
var uniqueParticipants = new Set();
var guests = event.getGuestList();
guests.forEach(guest => uniqueParticipants.add(guest.getEmail()));
creators.forEach(creator => uniqueParticipants.add(creator));
var participantCount = uniqueParticipants.size;
var durationInHours = (event.getEndTime() - event.getStartTime()) / 1000 / 60 / 60;
Logger.log(event.getTitle() + ": " + participantCount + " participant(s) - " + durationInHours + " hour(s)");
if (participantCount > (minNumberOfParticipants - 1)) {
var description = event.getDescription();
if (description.match("Estimated costs for this meeting:.*")) {
var regex = new RegExp('Estimated costs for this meeting:.*', 'gi');
description = description.replace(regex, "");
}
description = description.trim();
var costs = Math.floor(participantCount * durationInHours * averageHourlyRate);
description = description + "\n\nEstimated costs for this meeting: " + (costs) + "€";
Logger.log("New description for event '"+ event.getTitle() + "' is '" + description + "'");
event.setDescription(description);
}
}
}