Add optional stats files to heartbeat export - #1604
Conversation
Greptile SummaryAdds optional CSV and JSON statistics to heartbeat export ZIP archives.
Confidence Score: 2/5This PR should not merge until the stats option is reachable, historical weekly exports use the selected range and CSV labels are safely encoded. The user-facing flow cannot enable the feature, historical exports generate incomplete weekly statistics and formula-prefixed heartbeat labels remain active in generated CSV cells. Files Needing Attention: app/controllers/my/heartbeats_controller.rb, app/jobs/heartbeat_export_job.rb and app/services/dashboard_data/snapshots.rb
|
| Filename | Overview |
|---|---|
| app/controllers/my/heartbeats_controller.rb | Propagates the optional stats flag, but the existing user-facing forms never submit it. |
| app/jobs/heartbeat_export_job.rb | Adds streamed statistics files to the ZIP, but raw labels remain formula-active in CSVs and the new branch lacks tests. |
| app/services/dashboard_data/snapshots.rb | Adds export aggregation, but its weekly breakdown remains tied to the current dashboard window rather than the export range. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
U[Export request] --> C[Heartbeats controller]
C -->|include_stats| J[HeartbeatExportJob]
J --> H[Selected heartbeat scope]
H --> JSON[Heartbeat JSON]
H --> S[Processed export snapshot]
S --> CSV[Statistics CSV files]
S --> SJ[Statistics JSON]
JSON --> ZIP[ZIP archive]
CSV --> ZIP
SJ --> ZIP
ZIP --> B[Active Storage blob]
B --> M[Email download link]
Prompt To Fix All With AI
### Issue 1
app/controllers/my/heartbeats_controller.rb:13
**Stats option is unreachable**
When a user requests either export from the settings page, neither form submits `include_stats`, so this comparison always evaluates false and the archive never contains the new stats files.
### Issue 2
app/services/dashboard_data/snapshots.rb:256-259
**Weekly stats use wrong range**
When an export includes heartbeats older than the current twelve-week dashboard window, `weekly_project_stats` intersects the export scope with that fixed window, causing the weekly CSV and JSON stats to omit heartbeats that are present in the same archive.
### Issue 3
app/jobs/heartbeat_export_job.rb:115-117
**CSV labels remain formula-active**
When a project, language, editor, operating-system or category label starts with `=`, `+`, `-` or `@`, the CSV writer emits it unchanged, so spreadsheet software interprets the user-controlled value as a formula instead of inert text. **How this was verified:** The ingestion path preserves these prefixes and the new writer passes the resulting grouping keys directly to Ruby CSV.
### Issue 4
app/jobs/heartbeat_export_job.rb:59-64
**Stats branch lacks coverage**
The existing controller and job tests never enable `include_stats`, leaving the new parameter handling, archive filenames and generated CSV/JSON contents outside regression coverage.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "Add optional stats files to heartbeat ex..." | Re-trigger Greptile
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
Current checklist of things until ready for review:
#1606 Needs to be merged for this PR to work. |
Summary of the problem
These changes are made to provide the user an easier way to get the data shown in graphs.
Describe your changes
This pull request adds the ability to include detailed statistics in the heartbeat data export, providing users with additional CSV and JSON files containing breakdowns of their coding activity. The main changes involve updating the export flow to accept a new
include_statsparameter, generating various stats files, and enhancing the export job to bundle these files into the exported ZIP archive.Export Flow Enhancements:
my/heartbeats_controller.rbnow accept aninclude_statsparameter, which is passed to the export job to trigger stats file generation.Heartbeat Export Job Improvements:
HeartbeatExportJobnow accepts and handles theinclude_statsparameter, generating additional CSV and JSON statistics files (such as project durations, language stats, editor stats, weekly project stats, coding rhythm, etc.) and includes them in the ZIP archive if requested.Statistics Generation:
processed_export_snapshotwas added toDashboardData::Snapshotsto aggregate all relevant statistics for the export, including project, language, editor, OS, category breakdowns, weekly project stats, and coding rhythm.Other Minor Changes:
csvlibrary inheartbeat_export_job.rbto support CSV generation.These changes collectively allow users to optionally receive detailed, structured statistics about their coding activity alongside the standard heartbeat export.
Screenshots / Media