calendar-stats

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

calendar-stats, a program to compute statistics from Google calendars.

Summary

If you keep track of what you spend your time on by creating events in a Google Calendar, this program can help you compute some statistics based on those events, as long as you adhere to some conventions.

Features

Time range selection

By default the program looks at events that start before the beginning of the current week, and end before now.

You can change the start week by setting the -weeks parameter.

You can set arbitrary start or end by setting the -start or -end parameters to unambiguous values in formats understood by the dateparse library.

Note that events that begin before the start or finish after the end are not taken into account, even if they partially run into the selected time frame. This may change in the future.

Time spent per day

The program will count and print how much time overall the events took, per day.

When run against a calendar like the following:

Calendar screenshot

It will produce the output such as the following:

$ ./calendar-stats
[...]
Time spent per day:
2023-03-27: 1h45m0s
2023-03-28: 2h15m0s
2023-03-29: 1h15m0s

Note that it accounts correctly for overlapping events.

Time spent per category

If you provide a configuration file which explains how to group events into categories, the program will also count how much time was spent on each category. In case of overlapping events, the time is accounted proportionally.

With the above calendar and the following config file:

categories:
- name: mail
  match:
  - re: "read e?mail"

- name: meetings
  match:
  - re: "meeting"

- name: reviews
  match:
  - re: "^review:? "

The output will be:

$ ./calendar-stats
[...]
Time spent per category:
23.8% mail
52.4% meetings
19.0% reviews
Unrecognized:
2023-03-28T10:00:00+02:00      15m0s  reaad mail

The program will also list unrecognized events, i.e. events that do not match any category.

Event summary corrections
  1. Optionally, the program can save unrecognized events into a corrections file.
  2. The user can then change the summary (title) of the events in this file using a text editor.
  3. On subsequent invocation, the program will update event summaries in the calendar based on the edited file.

This is a faster way to retitle multiple events than edit them one by one in the Google Calendar interface directly.

Taking the above calendar as an example, the "reaad mail" event summary contains a typo. Running the program with option --corrections corrections.yaml, the following file will be created:

corrections:
    - id: 2lb6peh9kscthpiaen2jidjemj
      summary: reaad mail
      organizer: Marcin Owsiany

We use a text editor to fix the summary: line and run the program again:

$ ./calendar-stats -weeks 5 --corrections corrections.yaml 
2023/04/15 10:23:20 Updating summary of 1 events...
2023/04/15 10:23:22 Summaries updated.
Time spent per day:
2023-03-27: 1h45m0s
2023-03-28: 2h15m0s
2023-03-29: 1h15m0s
Time spent per category:
28.6% mail
52.4% meetings
19.0% reviews

The summary was updated in Google Calendar, and subsequently all events are recognized. The resulting corrections file is now nearly empty:

corrections: []

How to run the program

You can build your own binary by running go build . in the top directory.

From time to time, binaries may be provided in the GitHub releases.

Either way, in order to actually authenticate against Google Calendar API, the program needs a credentials.json file, which represents an OAuth2 Client. See instructions for generating a client for a desktop application.

Once you save it in the current directory, the program will authenticate you to Google Calendar using a web browser and save a token.json file on the first invocation.

See above for examples and use the -h parameter to see available options.

Documentation

Overview

calendar-stats, a program to compute statistics from Google calendars. Copyright (C) 2023 Marcin Owsiany <marcin@owsiany.pl>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Directories

Path Synopsis
internal
core
calendar-stats, a program to compute statistics from Google calendars.
calendar-stats, a program to compute statistics from Google calendars.
flags
calendar-stats, a program to compute statistics from Google calendars.
calendar-stats, a program to compute statistics from Google calendars.
io
calendar-stats, a program to compute statistics from Google calendars.
calendar-stats, a program to compute statistics from Google calendars.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL