Skip to content

Commit f1a5f6f

Browse files
authored
Feature/git branch time tracking (#48)
* feat: add branch tracking and view storage data command * feat: add documentation for time tracking mechanism and todo list * feat: enhance branch tracking * feat: add project-specific branch filtering and update UI for branch selection * feat: add command to clear all time tracking data with confirmation prompt * feat: enhance project and branch tracking in documentation and update usage instructions * Update package.json
1 parent 4353eb1 commit f1a5f6f

11 files changed

Lines changed: 663 additions & 124 deletions

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Simple Coding Time Tracker is a powerful extension for Visual Studio Code that h
88
## Features
99

1010
- **Automatic Time Tracking**: Seamlessly tracks your coding time in the background.
11-
- **Project-based Tracking**: Organizes time data by project for easy analysis.
11+
- **Project and Branch Tracking**: Organizes time data by project and Git branches for comprehensive analysis.
1212
- **Smart Activity Detection**: Automatically pauses tracking during periods of inactivity.
1313
- **Focused Work Detection**: Intelligently tracks time even when VS Code isn't focused.
1414
- **Interactive Data Visualization**:
@@ -37,10 +37,15 @@ Once installed, the extension will automatically start tracking your coding time
3737

3838
1. In the summary view, locate the search form
3939
2. Select a date range using the date pickers
40-
3. Optionally choose a specific project from the dropdown
40+
3. Filter by project and/or branch:
41+
- Choose a specific project to see all its branches
42+
- Select a branch to see time data for that specific branch
43+
- The branch dropdown automatically updates to show only branches from the selected project
4144
4. Click "Search" to apply filters
4245
5. Use "Reset" to clear all filters and refresh the view
4346

47+
The charts and visualizations will automatically update to reflect your selected project and branch filters.
48+
4449
### Configuration Options
4550

4651
You can customize the extension's behavior through VS Code settings:
@@ -100,6 +105,13 @@ For technical details about development, release process, and internal architect
100105

101106
## Changelog
102107

108+
### [0.4.0] - 2025-06-06
109+
- Added Git branch tracking to monitor time spent on different branches
110+
- Enhanced project view with branch-specific time tracking
111+
- Implemented dynamic branch filtering based on selected project
112+
- Improved charts to show time distribution across branches
113+
- Added branch-specific data in search results and visualizations
114+
103115
### [0.3.9] - 2025-05-25
104116
- Added Focus Timeout setting to intelligently track time when VS Code loses focus
105117
- Fixed version tracking in GitHub Actions workflow to prevent publishing issues

TIME_TRACKING.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Simple Coding Time Tracker - How It Works
2+
3+
This document explains how the time tracking mechanism works in Simple Coding Time Tracker (SCTT). It's written for both developers who want to understand the code and users who want to know what's happening behind the scenes.
4+
5+
## Core Concepts
6+
7+
### Time Units and Storage
8+
- Time is tracked in **minutes**
9+
- Data is stored as `TimeEntry` objects with:
10+
- Date: When the coding session occurred
11+
- Project: Which project was being worked on
12+
- Branch: Which git branch was active
13+
- TimeSpent: Duration in minutes
14+
15+
### Key Variables That Control Tracking
16+
17+
```typescript
18+
// These are the main timing control variables
19+
saveIntervalSeconds = 5 // How often to save time entries
20+
inactivityTimeoutSeconds = 300 // Stop tracking after 5 mins of inactivity
21+
focusTimeoutSeconds = 60 // Continue tracking for 1 min after losing focus
22+
```
23+
24+
## How Time Tracking Works
25+
26+
### 1. Starting a Tracking Session
27+
28+
A tracking session starts when:
29+
- You start typing/moving cursor
30+
- VS Code window gains focus
31+
- You switch to a different file
32+
33+
The tracker records:
34+
- Start time (`startTime`)
35+
- Current project (`currentProject`)
36+
- Current git branch (`currentBranch`)
37+
38+
### 2. During Active Tracking
39+
40+
The tracker maintains three important intervals:
41+
42+
1. **Update Interval (1 second)**
43+
- Runs every second
44+
- Updates internal state
45+
- Used for real-time UI updates
46+
47+
2. **Save Interval (5 seconds by default)**
48+
- Saves your current session to database
49+
- Creates a new time entry
50+
- Resets the start time
51+
52+
3. **Activity Monitoring**
53+
- Tracks cursor movements, typing, file changes
54+
- Updates `lastCursorActivity` timestamp
55+
- Used to detect inactivity
56+
57+
### 3. Project & Branch Tracking
58+
59+
The tracker automatically handles:
60+
61+
- **Project Changes**
62+
- Detects when you switch between projects
63+
- Saves time separately for each project
64+
- Multi-root workspace aware
65+
66+
- **Branch Changes**
67+
- Monitors git branch changes
68+
- Creates separate time entries per branch
69+
- Perfect for tracking time across feature branches
70+
71+
### 4. When Tracking Stops
72+
73+
Tracking stops in these scenarios:
74+
75+
1. **Inactivity** (after 5 minutes by default)
76+
- No cursor movement
77+
- No typing
78+
- No file changes
79+
80+
2. **Lost Focus** (after 1 minute by default)
81+
- Switched to another application
82+
- Can be configured to wait longer
83+
84+
3. **Manual Stop**
85+
- VS Code is closed
86+
- Extension is disabled
87+
88+
### Database Structure
89+
90+
Time entries are stored with this structure:
91+
```typescript
92+
interface TimeEntry {
93+
date: string; // ISO date string (YYYY-MM-DD)
94+
project: string; // Project/workspace name
95+
timeSpent: number; // Duration in minutes
96+
branch: string; // Git branch name
97+
}
98+
```
99+
100+
## Configuration Options
101+
102+
You can customize tracking behavior:
103+
104+
1. **Save Interval** (`simpleCodingTimeTracker.saveInterval`)
105+
- How often to save time entries
106+
- Default: 5 seconds
107+
- Lower = More accurate but more writes
108+
109+
2. **Inactivity Timeout** (`simpleCodingTimeTracker.inactivityTimeout`)
110+
- How long to wait before stopping due to inactivity
111+
- Default: 300 seconds (5 minutes)
112+
- Higher = More lenient with breaks
113+
114+
3. **Focus Timeout** (`simpleCodingTimeTracker.focusTimeout`)
115+
- How long to continue tracking after losing window focus
116+
- Default: 60 seconds (1 minute)
117+
- Higher = Better for quick app switches
118+
119+
## Tips for Accurate Tracking
120+
121+
1. **Keep VS Code Focused**
122+
- Tracking is most accurate when VS Code remains your active window
123+
- Use the focus timeout setting if you frequently switch apps
124+
125+
2. **Branch Awareness**
126+
- Create branches for different features
127+
- Time is tracked separately per branch
128+
- Great for client billing
129+
130+
3. **Project Organization**
131+
- Use separate VS Code windows for different projects
132+
- Or use multi-root workspaces for clean separation
133+
134+
## Common Scenarios
135+
136+
1. **Multiple Projects Open**
137+
```
138+
Project A (main) → 30 mins
139+
Project B (feature) → 45 mins
140+
```
141+
Each gets tracked separately
142+
143+
2. **Branch Switching**
144+
```
145+
main → 1 hour
146+
feature/xyz → 30 mins
147+
```
148+
Time is split accurately per branch
149+
150+
3. **Taking Breaks**
151+
```
152+
10:00 - Start coding
153+
10:30 - Take break (no activity)
154+
10:35 - Tracking auto-stops
155+
10:40 - Resume coding (auto-starts)
156+
```
157+
158+
## Behind-the-Scenes Logic
159+
160+
1. **Activity Detection**
161+
- Monitors VS Code events
162+
- Cursor movements
163+
- Text changes
164+
- File switches
165+
- Git operations
166+
167+
2. **Time Calculation**
168+
```typescript
169+
duration = (currentTime - startTime) / 60000 // Convert ms to minutes
170+
```
171+
172+
3. **Session Management**
173+
- Small sessions are combined
174+
- Inactive periods are excluded
175+
- Branch/project switches create new sessions
176+
177+
## Developer Notes
178+
179+
Key files and their roles:
180+
- `timeTracker.ts`: Core tracking logic
181+
- `database.ts`: Time entry storage
182+
- `statusBar.ts`: Real-time UI updates
183+
- `summaryView.ts`: Time statistics and reports

TODO.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# TODO List
2+
3+
Quick capture for ideas and tasks while coding.
4+
## Guidelines
5+
- Use checkboxes `- [ ]` for actionable items
6+
- Use bullet points `-` for ideas and thoughts
7+
- Add date in parentheses (YYYY-MM-DD) when the task is done
8+
- Keep it simple and informal - this is your working todo list
9+
10+
## Immediate Tasks
11+
- [X] Listen for branch changes in real-time , save immediately when branch changes , start new session with new branch
12+
- [X] Add branch name to time entries
13+
- [ ] Update UI to show current branch in status bar
14+
- [ ] Branch dropdown in summary view
15+
- [ ] Add branch filter in time tracking summary
16+
- [ ] Handle missing branch data in older time entries
17+
- [ ] Fix race condition in branch detection during quick switches
18+
- [ ] Add proper handling for detached HEAD state
19+
- [ ] Implement data migration strategy for existing entries
20+
21+
## Ideas
22+
- Maybe add a quick pause button in status bar?
23+
- A variable maybe for tracking the active coding session duration, and it will notify when it exceeds a certain threshold.
24+
25+
## Bug Fixes
26+
27+
28+
## Ideas
29+
- Add branch history view in time tracking summary
30+
- Show branch switching patterns in analytics
31+
- Add branch-specific coding time statistics
32+
33+

package-lock.json

Lines changed: 34 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "simple-coding-time-tracker",
33
"displayName": "Simple Coding Time Tracker",
44
"description": "Track and visualize your coding time across projects",
5-
"version": "0.3.9",
5+
"version": "0.4.0",
66
"publisher": "noorashuvo",
77
"license": "MIT",
88
"icon": "icon-sctt.png",
@@ -22,7 +22,7 @@
2222
"properties": {
2323
"simpleCodingTimeTracker.saveInterval": {
2424
"type": "number",
25-
"default": 5,
25+
"default": 30,
2626
"description": "How often to save coding time data (in seconds)"
2727
},
2828
"simpleCodingTimeTracker.inactivityTimeout": {
@@ -36,13 +36,23 @@
3636
"description": "If you switch away from VS Code, continue counting as coding time for up to this many seconds before pausing."
3737
}
3838
}
39-
}, "commands": [
39+
},
40+
"commands": [
4041
{
4142
"command": "simpleCodingTimeTracker.showSummary",
4243
"title": "SCTT: Show Coding Time Summary"
44+
},
45+
{
46+
"command": "simpleCodingTimeTracker.viewStorageData",
47+
"title": "SCTT: View Time Tracking Data"
48+
},
49+
{
50+
"command": "coding-time-tracker.clearAllData",
51+
"title": "Clear All Time Tracking Data"
4352
}
4453
]
45-
}, "scripts": {
54+
},
55+
"scripts": {
4656
"vscode:prepublish": "npm run package",
4757
"compile": "webpack",
4858
"watch": "webpack --watch",
@@ -64,6 +74,9 @@
6474
"webpack": "^5.99.8",
6575
"webpack-cli": "^6.0.1"
6676
},
77+
"dependencies": {
78+
"simple-git": "^3.27.0"
79+
},
6780
"repository": {
6881
"type": "git",
6982
"url": "https://github.com/twentyTwo/vsc-ext-coding-time-tracker.git"

0 commit comments

Comments
 (0)