Skip to content

Time Tracking Algorithm

Michael Schenk edited this page Jul 4, 2016 · 7 revisions

GTM plug-ins listen for editor events, such as reading and writing, to save tiny event files in a directory within the root of the Git project directory. The event files are created from the plugin by calling gtm record <path/file>.

Each event file is timestamped by Unix time and contains the relative path of the file being tracked.

.gtm
├── 1467590059.event
├── 1467590268.event
├── 1467590285.event
├── 1467590302.event
├── 1467590338.event
├── 1467590492.event
├── 1467590501.event
├── 1467590549.event
├── 1467591748.event
└── 1467591763.event
> cat .gtm/1467591763.event
appveyor.yml

These event files are only created as needed to properly track the time spent in a file. For example, if you are reading and writing a single file an event file will only be created every 30 seconds.

After you are done editing and then commit your work, gtm commit --yes is called via a Git post commit hook to calculate the time spent. The algorithm organizes all event files into one minute epoch windows.

An epoch window is calculated as the following ( Unix time of event / 60 ) * 60. Here's an example in Go. Keep in mind this is integer division and the result will be truncated.

For the set of files in an epoch window, each file is allocated a percentage of the time (60 seconds) based on the number of events for that file vs the total number of events for all files in the window. In addition, idle event time may be added for up to two minutes if no editor events are triggered. Currently the amount of idle event time is not configurable but we may provide that in the future. We also may increase the default value if it proves to be to conservative.